source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | spec/integration/rom/factory_spec.rb | Ruby | mit | 84 | main | 45,028 | # frozen_string_literal: true
RSpec.describe ROM::Factory do
include_context "relations"
subject(:factories) do
ROM::Factory.configure do |config|
config.rom = rom
end
end
describe "factory is not defined" do
it "raises error for persistable" do
expect { factories[:not_defined] }
... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | spec/shared/relations.rb | Ruby | mit | 84 | main | 2,761 | # frozen_string_literal: true
RSpec.shared_context "relations" do
include_context "database"
before do
conn.create_table?(:users) do
primary_key :id
column :last_name, String, null: false
column :first_name, String, null: false
column :alias, String, null: true
column :email, Str... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | spec/shared/database.rb | Ruby | mit | 84 | main | 345 | # frozen_string_literal: true
require "rom-core"
RSpec.shared_context "database" do
let(:conf) do
ROM::Configuration.new(:sql, DB_URI)
end
let(:rom) do
ROM.container(conf)
end
let(:conn) do
conf.gateways[:default].connection
end
after do
conn.disconnect
end
let(:relations) do
... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | spec/unit/rom/factory/builder_spec.rb | Ruby | mit | 84 | main | 7,795 | # frozen_string_literal: true
require "rom/factory/builder"
RSpec.describe ROM::Factory::Builder do
subject(:builder) do
ROM::Factory::Builder.new(ROM::Factory::AttributeRegistry.new(attributes),
relation: relation,
struct_namespace: {namespace: ROM::S... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | spec/unit/rom/factory/attribute_registry_spec.rb | Ruby | mit | 84 | main | 610 | # frozen_string_literal: true
require "rom/factory/attribute_registry"
RSpec.describe ROM::Factory::AttributeRegistry do
subject(:registry) { ROM::Factory::AttributeRegistry.new(elements) }
let(:elements) do
[email_attr, id_attr, name_attr]
end
let(:name_attr) do
value(:name, "Jane")
end
let(:e... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory.rb | Ruby | mit | 84 | main | 740 | # frozen_string_literal: true
require "dry/core"
require "dry/configurable"
require "dry/struct"
require "rom/factory/factories"
module ROM
# Main ROM::Factory API
#
# @api public
module Factory
DEFAULT_NAME = "Factories"
# Configure a new factory
#
# @example
# MyFactory = ROM::Factor... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/sequences.rb | Ruby | mit | 84 | main | 664 | # frozen_string_literal: true
require "concurrent/map"
require "singleton"
module ROM
module Factory
# @api private
class Sequences
include Singleton
# @api private
attr_reader :registry
# @api private
def self.[](relation)
key = :"#{relation.gateway}-#{relation.name.... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attributes.rb | Ruby | mit | 84 | main | 271 | # frozen_string_literal: true
module ROM
module Factory
include Dry::Core::Constants
end
end
require "rom/factory/attributes/value"
require "rom/factory/attributes/callable"
require "rom/factory/attributes/sequence"
require "rom/factory/attributes/association" |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/registry.rb | Ruby | mit | 84 | main | 654 | # frozen_string_literal: true
require "rom/factory/constants"
module ROM
module Factory
# @api private
class Registry
# @!attribute [r] elements
# @return [Hash] a hash with factory builders
attr_reader :elements
# @api private
def initialize
@elements = {}
end... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/constants.rb | Ruby | mit | 84 | main | 365 | # frozen_string_literal: true
module ROM
module Factory
class FactoryNotDefinedError < StandardError
def initialize(name)
super("Factory +#{name}+ not defined")
end
end
class UnknownFactoryAttributes < StandardError
def initialize(attrs)
super("Unknown attributes: #{att... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/builder.rb | Ruby | mit | 84 | main | 2,313 | # frozen_string_literal: true
require "rom/struct"
require "rom/initializer"
require "rom/factory/tuple_evaluator"
require "rom/factory/builder/persistable"
module ROM::Factory
# @api private
class Builder
extend ROM::Initializer
include Dry::Core::Constants
# @!attribute [r] attributes
# @ret... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/dsl.rb | Ruby | mit | 84 | main | 6,520 | # frozen_string_literal: true
require "faker"
require "rom/factory/builder"
require "rom/factory/attribute_registry"
require "rom/factory/attributes"
module ROM
module Factory
extend ::Dry::Core::Cache
class << self
# @api private
def fake(*args, unique: false, **options)
factory, prod... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/tuple_evaluator.rb | Ruby | mit | 84 | main | 6,106 | # frozen_string_literal: true
require "rom/factory/sequences"
module ROM
module Factory
# @api private
class TupleEvaluator
class TupleEvaluatorError < StandardError
attr_reader :original_exception
def initialize(relation, original_exception, attrs, traits, assoc_attrs)
supe... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attribute_registry.rb | Ruby | mit | 84 | main | 1,347 | # frozen_string_literal: true
require "tsort"
module ROM
module Factory
# @api private
class AttributeRegistry
include Enumerable
include TSort
# @api private
attr_reader :elements
# @api private
def initialize(elements = [])
@elements = elements
end
... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/factories.rb | Ruby | mit | 84 | main | 7,175 | # frozen_string_literal: true
require "rom/initializer"
require "rom/struct"
require "rom/factory/dsl"
require "rom/factory/registry"
module ROM::Factory
# In-memory builder API
#
# @api public
class Structs
# @!attribute [r] registry
# @return [Hash<Symbol=>Builder>]
attr_reader :registry
... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attributes/value.rb | Ruby | mit | 84 | main | 534 | # frozen_string_literal: true
module ROM::Factory
module Attributes
# @api private
class Value
attr_reader :name, :value
# @api private
def initialize(name, value)
@name = name
@value = value
end
# @api private
def call(attrs = EMPTY_HASH)
return ... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attributes/association.rb | Ruby | mit | 84 | main | 5,539 | # frozen_string_literal: true
module ROM::Factory
module Attributes
# @api private
# rubocop:disable Style/OptionalArguments
module Association
class << self
def new(assoc, ...)
const_get(assoc.definition.type).new(assoc, ...)
end
end
# @api private
clas... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attributes/sequence.rb | Ruby | mit | 84 | main | 552 | # frozen_string_literal: true
module ROM::Factory
module Attributes
class Sequence
attr_reader :name, :count, :block
def initialize(name, &block)
@name = name
@count = 0
@block = block
end
def call(*args)
block.call(increment, *args)
end
def ... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/attributes/callable.rb | Ruby | mit | 84 | main | 771 | # frozen_string_literal: true
module ROM::Factory
module Attributes
# @api private
class Callable
attr_reader :name, :dsl, :block
# @api private
def initialize(name, dsl, block)
@name = name
@dsl = dsl
@block = block
end
# @api private
def call(at... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | lib/rom/factory/builder/persistable.rb | Ruby | mit | 84 | main | 1,714 | # frozen_string_literal: true
require "delegate"
module ROM
module Factory
class Builder
# @api private
class Persistable < SimpleDelegator
# @api private
attr_reader :builder
# @api private
attr_reader :relation
# @api private
def initialize(builder... |
github | rom-rb/rom-factory | https://github.com/rom-rb/rom-factory | benchmarks/basic.rb | Ruby | mit | 84 | main | 1,224 | # frozen_string_literal: true
require "rom-factory"
require "rom-core"
require "active_record"
require "factory_bot"
require "fabrication"
require "benchmark/ips"
DATABASE_URL = "postgres://localhost/rom_factory_bench"
rom = ROM.container(:sql, DATABASE_URL) do |conf|
conf.default.connection.create_table?(:users) ... |
github | kdan-mobile-software-ltd/secret-keeper | https://github.com/kdan-mobile-software-ltd/secret-keeper | secret-keeper.gemspec | Ruby | mit | 84 | master | 916 | Gem::Specification.new do |s|
s.name = 'secret-keeper'
s.version = File.read("./VERSION.md")
s.platform = Gem::Platform::RUBY
s.summary = 'Keep all your secret files within openssl'
s.description = 'A Secret keeper'
s.authors = ['Ray Lee']
s.email = 'ray-lee@kdanmobile.com'
s... |
github | kdan-mobile-software-ltd/secret-keeper | https://github.com/kdan-mobile-software-ltd/secret-keeper | spec/secret-keeper_spec.rb | Ruby | mit | 84 | master | 5,485 | require 'yaml'
require 'fileutils'
require 'secret-keeper'
describe SecretKeeper do
before(:each) do
ENV['SECRET_KEEPER'] = 'PASSWORD_HERE'
FileUtils.copy_entry('./example', './example_backup')
end
after(:each) do
FileUtils.rm_r('./example')
FileUtils.mv('./example_backup', './example')
end
... |
github | kdan-mobile-software-ltd/secret-keeper | https://github.com/kdan-mobile-software-ltd/secret-keeper | lib/secret-keeper.rb | Ruby | mit | 84 | master | 3,817 | require 'openssl'
require 'yaml'
class SecretKeeper
attr_reader :tasks, :options
def self.encrypt_files
printer = ['Encrypting...']
sk = SecretKeeper.new
printer << '(production config removed)' if sk.options['remove_production']
printer << '(source files removed)' if sk.options['remove_source']
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | epub-parser.gemspec | Ruby | mit | 83 | master | 2,224 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "epub/parser/version"
Gem::Specification.new do |s|
s.name = "epub-parser"
s.version = EPUB::Parser::VERSION
s.authors = ["KITAITI Makoto"]
s.email = ["KitaitiMakoto@gmail.com"]
s.homepage = "https://kitait... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | Gemfile | Ruby | mit | 83 | master | 394 | source 'https://rubygems.org'
gemspec
group :development do
if ENV["EPUB_CFI_PATH"]
gem "epub-cfi", path: ENV["EPUB_CFI_PATH"]
end
if ENV['EPUB_MAKER_PATH']
gem 'epub-maker', path: ENV["EPUB_MAKER_PATH"]
end
if RUBY_PLATFORM.match /darwin/
gem 'terminal-notifier'
end
end
group :development, ... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | rakelib/test.rake | Ruby | mit | 83 | master | 1,697 | require 'rake/clean'
require 'rake/testtask'
require 'epub/maker'
require "tmpdir"
require 'archive/zip'
task :test => 'test:default'
namespace :test do
task :default => [:test, :test_ocf_physical_container_zipruby, :test_ocf_physical_container_rubyzip]
desc 'Build test fixture EPUB file'
task :build => [:clea... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | rakelib/doc.rake | Ruby | mit | 83 | master | 583 | require 'yard'
require 'rdoc/task'
task :doc => 'doc:default'
namespace :doc do
task :default => [:yard, :rdoc]
YARD::Rake::YardocTask.new
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include %w[
lib/**/*.rb
README.adoc
CHANGELOG.adoc
MIT-LICENSE
docs/**/*.adoc
docs/**/*... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | examples/find-elements-and-cfis.rb | Ruby | mit | 83 | master | 1,189 | require 'English'
require 'epub/parser'
require 'epub/cfi'
require 'nokogiri'
def usage
<<EOS
USAGE:
ruby #{$PROGRAM_NAME} ELEMENT EPUB
EOS
end
def main(argv)
elem_name = argv.shift
epub_path = argv.shift
if elem_name.nil? or epub_path.nil?
abort usage
end
spine_step = EPUB::CFI::Step.new(6)
ep... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | examples/aggregate-contents-from-web.rb | Ruby | mit | 83 | master | 977 | require 'pathname'
require 'tmpdir'
require 'epub/parser'
EPUB_URI = URI.parse(ARGV.shift)
DOWNLOAD_DIR = Pathname.new(ARGV.shift || Dir.mktmpdir('epub-parser'))
$stderr.puts <<EOI
Started downloading EPUB contents...
from: #{EPUB_URI}
to: #{DOWNLOAD_DIR}
EOI
# Make it possible to use URI as EPUB file path
EPUB... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | examples/exctract-content-using-cfi.rb | Ruby | mit | 83 | master | 3,929 | # coding: utf-8
# Preparation
#
# % cd examples
# % wget -O accessible-epub3.epub 'https://drive.google.com/uc?export=download&id=0B9g8D2Y-6aPLRmFKRTNIam93RTQ'
#
# Execution
#
# % ruby exctract-content-using-cfi.rb accessible-epub3.epub '/6/10!/4/2/4'
# <p>Accessibility is a difficult concept to define. There’s... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_epub.rb | Ruby | mit | 83 | master | 668 | require_relative 'helper'
require 'epub/book'
class TestEUPB < Test::Unit::TestCase
def setup
@file = 'test/fixtures/book.epub'
end
def test_each_page_on_spine_returns_enumerator_when_block_not_given
book = EPUB::Parser.parse(@file)
assert_kind_of Enumerator, book.each_page_on_spine
end
def tes... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser.rb | Ruby | mit | 83 | master | 2,579 | # coding: utf-8
require File.expand_path 'helper', File.dirname(__FILE__)
class MyBook
include EPUB::Book::Features
end
class TestParser < Test::Unit::TestCase
def setup
@parser = EPUB::Parser.new 'test/fixtures/book.epub'
end
def test_parse
assert_instance_of EPUB::Book, @parser.parse
book = Ob... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_content_document.rb | Ruby | mit | 83 | master | 4,590 | # -*- coding: utf-8 -*-
require_relative 'helper'
class TestContentDocument < Test::Unit::TestCase
include EPUB::ContentDocument
def test_top_level?
manifest = EPUB::Publication::Package::Manifest.new
spine = EPUB::Publication::Package::Spine.new
item1 = EPUB::Publication::Package::Manifest::Item.new... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_fixed_layout.rb | Ruby | mit | 83 | master | 8,192 | require_relative 'helper'
require 'epub/book'
require 'epub/publication'
class EPUB::Publication::Package
include EPUB::Publication::FixedLayout
end
class TestFixedLayout < Test::Unit::TestCase
include EPUB::Publication
class TestPackage < TestFixedLayout
def test_package_dont_use_fixed_layout_by_default
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser_publication.rb | Ruby | mit | 83 | master | 7,654 | # -*- coding: utf-8 -*-
require File.expand_path 'helper', File.dirname(__FILE__)
class TestParserPublication < Test::Unit::TestCase
def setup
opf = File.read("test/fixtures/book/OPS/ルートファイル.opf")
@opf = EPUB::Parser::XMLDocument.new(opf)
@parser = EPUB::Parser::Publication.new(opf)
@package = @parse... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_publication.rb | Ruby | mit | 83 | master | 15,241 | # coding: utf-8
require_relative 'helper'
require 'epub/publication'
class TestPublication < Test::Unit::TestCase
include EPUB::Publication
def setup
@package = EPUB::Publication::Package.new
end
def test_package_clear_package_attribute_of_submodules_when_attribute_writer_called
metadata = EPUB::Publi... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser_xmldocument.rb | Ruby | mit | 83 | master | 2,225 | # coding: utf-8
require_relative "helper"
class TestParserXMLDocument < Test::Unit::TestCase
def setup
@container = File.read("test/fixtures/book/META-INF/container.xml")
@opf = File.read("test/fixtures/book/OPS/ルートファイル.opf")
@nav = File.read("test/fixtures/book/OPS/nav.xhtml")
@backends = [:REXML, :... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_searcher.rb | Ruby | mit | 83 | master | 7,332 | # -*- coding: utf-8 -*-
require_relative 'helper'
require 'epub/searcher'
require 'epub/cfi'
class TestSearcher < Test::Unit::TestCase
class TestPublication < self
def setup
super
opf_path = File.expand_path('../fixtures/book/OPS/ルートファイル.opf', __FILE__)
nav_path = File.expand_path('../fixtures/... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_ocf_physical_container_zipruby.rb | Ruby | mit | 83 | master | 404 | begin
require "epub/ocf/physical_container/zipruby"
require_relative "test_ocf_physical_container_base"
class TestZipruby < TestOCFPhysicalContainerBase
include ConcreteContainer
def setup
super
@class = EPUB::OCF::PhysicalContainer::Zipruby
@container = @class.new(@container_path)
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/helper.rb | Ruby | mit | 83 | master | 1,217 | Encoding.default_external = 'UTF-8'
require 'simplecov'
SimpleCov.start do
add_filter /test|deps/
end
require 'pp'
require 'test/unit'
require 'test/unit/rr'
require 'test/unit/notify'
require 'epub/parser'
if ENV["XML_BACKEND"]
EPUB::Parser::XMLDocument.backend = ENV["XML_BACKEND"].to_sym
end
module ConcreteCon... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser_content_document.rb | Ruby | mit | 83 | master | 1,835 | # -*- coding: utf-8 -*-
require_relative 'helper'
class TestParserContentDocument < Test::Unit::TestCase
def setup
@manifest = EPUB::Publication::Package::Manifest.new
%w[item-1.xhtml item-2.xhtml nav.xhtml].each.with_index do |href, index|
item = EPUB::Publication::Package::Manifest::Item.new
it... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_ocf_physical_container.rb | Ruby | mit | 83 | master | 1,923 | # coding: utf-8
require_relative "test_ocf_physical_container_base"
require "epub/ocf/physical_container/ruzip"
class TestOCFPhysicalContainer < TestOCFPhysicalContainerBase
def test_read
assert_equal @content, EPUB::OCF::PhysicalContainer.read(@container_path, @path).force_encoding('UTF-8')
end
class TestU... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_inspect.rb | Ruby | mit | 83 | master | 3,267 | require_relative 'helper'
require 'epub'
class TestInspect < Test::Unit::TestCase
class TestPackage < TestInspect
include EPUB::Publication
def setup
@package = Package.new
end
def test_package_inspects_object_id
assert_match (@package.__id__ << 1).to_s(16), @package.inspect
end
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser_fixed_layout.rb | Ruby | mit | 83 | master | 560 | require_relative 'helper'
require 'epub/parser'
class TestParserFixedLayout < Test::Unit::TestCase
def test_using_fixed_layout_is_true_when_rendition_property_in_package_prefix
opf = <<OPF
<package version="3.0"
unique-identifier="pub-id"
xmlns="http://www.idpf.org/2007/opf"
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_parser_ocf.rb | Ruby | mit | 83 | master | 1,519 | # -*- coding: utf-8 -*-
require File.expand_path 'helper', File.dirname(__FILE__)
class TestParserOCF < Test::Unit::TestCase
def setup
file = 'test/fixtures/book.epub'
EPUB::OCF::PhysicalContainer.open(file) {|container|
@parser = EPUB::Parser::OCF.new(container)
}
@container_xml = File.read("t... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_ocf_physical_container_base.rb | Ruby | mit | 83 | master | 286 | require_relative "helper"
require "epub/ocf/physical_container"
class TestOCFPhysicalContainerBase < Test::Unit::TestCase
def setup
@container_path = 'test/fixtures/book.epub'
@path = 'OPS/nav.xhtml'
@content = File.read(File.join('test/fixtures/book', @path))
end
end |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | test/test_ocf_physical_container_rubyzip.rb | Ruby | mit | 83 | master | 331 | require_relative "helper"
require_relative "test_ocf_physical_container_base"
require "epub/ocf/physical_container/rubyzip"
class TestRubyzip < TestOCFPhysicalContainerBase
include ConcreteContainer
def setup
super
@class = EPUB::OCF::PhysicalContainer::Rubyzip
@container = @class.new(@container_path)... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/metadata.rb | Ruby | mit | 83 | master | 4,769 | require 'set'
module EPUB
class Metadata
include Inspector::PublicationModel
DC_ELEMS = [:identifiers, :titles, :languages] +
[:contributors, :coverages, :creators, :dates, :descriptions, :formats, :publishers,
:relations, :rights, :sources, :subjects, :types]
# Used for C... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser.rb | Ruby | mit | 83 | master | 4,130 | require 'epub'
require 'epub/constants'
require 'epub/book'
module EPUB
class Parser
class << self
# Parse an EPUB file
#
# @example
# EPUB::Parser.parse('path/to/book.epub') # => EPUB::Book object
#
# @example
# class MyBook
# include EPUB::Book::Feature... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/inspector.rb | Ruby | mit | 83 | master | 1,204 | module EPUB
module Inspector
INSTANCE_VARIABLES_OPTION = {:exclude => []}
SIMPLE_TEMPLATE = "#<%{class}:%{object_id}>"
def inspect_simply
SIMPLE_TEMPLATE % {
:class => self.class,
:object_id => inspect_object_id
}
end
def inspect_object_id
(__id__ << 1).to_s(16)... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/constants.rb | Ruby | mit | 83 | master | 1,400 | module EPUB
NAMESPACES = {
'xml' => 'http://www.w3.org/XML/1998/namespace',
'dc' => 'http://purl.org/dc/elements/1.1/',
'ocf' => 'urn:oasis:names:tc:opendocument:xmlns:container',
'opf' => 'http://www.idpf.org/2007/opf',
'xhtml' => 'http://www.w3.org/1999/xhtml',
'epub' => 'http://ww... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/searcher.rb | Ruby | mit | 83 | master | 556 | require 'epub/searcher/result'
require 'epub/searcher/publication'
require 'epub/searcher/xhtml'
module EPUB
module Searcher
class << self
def search_text(epub, word, **options)
Publication.search_text(epub.package, word, options)
end
def search_element(epub, css: nil, xpath: nil, name... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/searcher/xhtml.rb | Ruby | mit | 83 | master | 5,677 | require 'epub'
require 'epub/parser/xml_document'
module EPUB
module Searcher
class XHTML
using Parser::XMLDocument::Refinements
ALGORITHMS = {}
class << self
# @param element [REXML::Element, REXML::Document, Oga::XML::ELement, Oga::XML::Document, Nokogiri::XML::Element, Nokogiri::XM... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/searcher/result.rb | Ruby | mit | 83 | master | 2,985 | require 'epub/cfi'
module EPUB
module Searcher
class Result
class << self
# @example
# Result.aggregate_step_intersection([a, b, c], [a, b, d]) # => [[a, b], [c], [d]]
# @example
# Result.aggregate_step_intersection([a, b, c], [a, d, c]) # => [[a], [b, c], [d, c]]
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/searcher/publication.rb | Ruby | mit | 83 | master | 5,511 | require 'epub/publication'
require "epub/parser/xml_document"
module EPUB
module Searcher
class Publication
using Parser::XMLDocument::Refinements
class << self
def search_text(package, word, **options)
new(package).search_text(word, **options)
end
def search_eleme... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/package.rb | Ruby | mit | 83 | master | 2,362 | module EPUB
module Publication
class Package
include Inspector
CONTENT_MODELS = [:metadata, :manifest, :spine, :guide, :bindings]
RESERVED_VOCABULARY_PREFIXES = {
'' => 'http://idpf.org/epub/vocab/package/#',
'dcterms' => 'http://purl.org/dc/terms/',
'marc' => ... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/fixed_layout.rb | Ruby | mit | 83 | master | 7,311 | module EPUB
module Publication
module FixedLayout
PREFIX_KEY = 'rendition'.freeze
PREFIX_VALUE = 'http://www.idpf.org/vocab/rendition/#'.freeze
RENDITION_PROPERTIES = {
'layout' => ['reflowable'.freeze, 'pre-paginated'.freeze].freeze,
'orientation' => ['auto'.freeze, 'lands... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/package/manifest.rb | Ruby | mit | 83 | master | 8,797 | require 'set'
require 'addressable/uri'
require 'rchardet'
require 'epub/constants'
require 'epub/parser/content_document'
module EPUB
module Publication
class Package
class Manifest
include Inspector::PublicationModel
attr_accessor :package,
:id
def initiali... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/package/spine.rb | Ruby | mit | 83 | master | 3,168 | require 'set'
module EPUB
module Publication
class Package
class Spine
include Inspector::PublicationModel
attr_accessor :package,
:id, :toc, :page_progression_direction
attr_reader :itemrefs
def initialize
@itemrefs = []
end
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/package/bindings.rb | Ruby | mit | 83 | master | 608 | module EPUB
module Publication
class Package
class Bindings
include Inspector::PublicationModel
attr_accessor :package
def initialize
@media_types = {}
end
def <<(media_type)
@media_types[media_type.media_type] = media_type
end
d... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/publication/package/guide.rb | Ruby | mit | 83 | master | 1,542 | module EPUB
module Publication
class Package
class Guide
include Inspector::PublicationModel
attr_accessor :package, :references
def initialize
Reference::TYPES.each do |type|
variable_name = '@' + type.gsub('-', '_')
instance_variable_set variable_... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/publication.rb | Ruby | mit | 83 | master | 4,900 | require 'strscan'
require 'epub/publication'
require 'epub/constants'
require 'epub/parser/metadata'
module EPUB
class Parser
class Publication
using XMLDocument::Refinements
include Metadata
class << self
def parse(container, file)
opf = container.read(Addressable::URI.unenc... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/xml_document.rb | Ruby | mit | 83 | master | 557 | module EPUB
class Parser
class XMLDocument
class << self
attr_accessor :backend
def new(xml)
case backend
when :Oga
Oga.parse_xml(xml)
when :Nokogiri
Nokogiri.XML(xml)
else
REXML::Document.new(xml)
end
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/metadata.rb | Ruby | mit | 83 | master | 3,661 | module EPUB
class Parser
module Metadata
using XMLDocument::Refinements
def parse_metadata(elem, unique_identifier_id, default_namespace)
metadata = EPUB::Publication::Package::Metadata.new
id_map = {}
default_namespace_uri = EPUB::NAMESPACES[default_namespace]
elem.e... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/content_document.rb | Ruby | mit | 83 | master | 4,963 | require 'epub/content_document'
require 'epub/constants'
require 'epub/parser/xml_document'
module EPUB
class Parser
class ContentDocument
using XMLDocument::Refinements
# @param [EPUB::Publication::Package::Manifest::Item] item
def initialize(item)
@item = item
end
def pa... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/ocf.rb | Ruby | mit | 83 | master | 2,471 | require 'epub/constants'
require 'epub/ocf'
require 'epub/ocf/physical_container'
require 'epub/parser/metadata'
require "epub/parser/xml_document"
module EPUB
class Parser
class OCF
using XMLDocument::Refinements
include Metadata
DIRECTORY = 'META-INF'
class << self
def parse(c... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/xml_document/refinements/nokogiri.rb | Ruby | mit | 83 | master | 756 | require "nokogiri"
module EPUB
class Parser
class XMLDocument
module Refinements
module Nokogiri
refine ::Nokogiri::XML::Node do
def each_element_by_xpath(xpath, namespaces = nil, &block)
xpath(xpath, namespaces).each &block
end
def attri... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/xml_document/refinements/oga.rb | Ruby | mit | 83 | master | 2,152 | require "oga"
module EPUB
class Parser
class XMLDocument
module Refinements
module Oga
[::Oga::XML::Document, ::Oga::XML::Node].each do |klass|
refine klass do
[
[:document, ::Oga::XML::Document],
[:element, ::Oga::XML::Element],
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/parser/xml_document/refinements/rexml.rb | Ruby | mit | 83 | master | 1,249 | require "rexml/document"
module EPUB
class Parser
class XMLDocument
module Refinements
module REXML
[::REXML::Element, ::REXML::Text].each do |klass|
refine klass do
%i[document element text].each do |type|
define_method "#{type}?" do
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/book/features.rb | Ruby | mit | 83 | master | 3,015 | require 'forwardable'
module EPUB
class Book
module Features
extend Forwardable
attr_reader :ocf
attr_accessor :epub_file
# When writing, sets +ocf.book+ to self.
# @param [OCF]
def ocf=(mod)
@ocf = mod
mod.book = self
mod
end
# @return [A... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container.rb | Ruby | mit | 83 | master | 1,735 | require 'monitor'
require 'epub/ocf/physical_container/archive_zip'
require 'epub/ocf/physical_container/unpacked_directory'
require 'epub/ocf/physical_container/unpacked_uri'
module EPUB
class OCF
class PhysicalContainer
class NoEntry < StandardError
class << self
def from_error(error)
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/container.rb | Ruby | mit | 83 | master | 596 | module EPUB
class OCF
class Container
FILE = 'container.xml'
attr_reader :rootfiles
def initialize
@rootfiles = []
end
# syntax sugar
def rootfile
rootfiles.first
end
class Rootfile
attr_accessor :full_path, :media_type,
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/rubyzip.rb | Ruby | mit | 83 | master | 923 | require "zip"
module EPUB
class OCF
class PhysicalContainer
class Rubyzip < self
def open
orig_encoding = Zip.force_entry_names_encoding
begin
Zip.force_entry_names_encoding = "UTF-8"
Zip::File.open @container_path do |archive|
@monitor.sync... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/unpacked_directory.rb | Ruby | mit | 83 | master | 353 | module EPUB
class OCF
class PhysicalContainer
class UnpackedDirectory < self
def open
yield self
end
def read(path_name)
::File.read(::File.join(@container_path, path_name))
rescue ::Errno::ENOENT => error
raise NoEntry.from_error(error)
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/ruzip.rb | Ruby | mit | 83 | master | 639 | require "ruzip"
module EPUB
class OCF
class PhysicalContainer
class RuZip < self
def open
@monitor.synchronize do
@archive = ::RuZip::Archive.new(@container_path)
begin
yield self
ensure
@archive = nil
end
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/archive_zip.rb | Ruby | mit | 83 | master | 1,779 | require 'archive/zip'
module EPUB
class OCF
class PhysicalContainer
class ArchiveZip < self
def initialize(container_path)
super
@entries = {}
@last_iterated_entry_index = 0
end
def open
Archive::Zip.open @container_path do |archive|
... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/zipruby.rb | Ruby | mit | 83 | master | 848 | require 'zipruby'
module EPUB
class OCF
class PhysicalContainer
class Zipruby < self
def open
Zip::Archive.open @container_path do |archive|
@monitor.synchronize do
begin
@archive = archive
yield self
rescue ::Zip::Er... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/ocf/physical_container/unpacked_uri.rb | Ruby | mit | 83 | master | 909 | require 'open-uri'
module EPUB
class OCF
class PhysicalContainer
class UnpackedURI < self
# EPUB URI: http://example.net/path/to/book/
# container.xml: http://example.net/path/to/book/META-INF/container.xml
# @param [URI, String] container_path URI of EPUB container's root directory... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/content_document/xhtml.rb | Ruby | mit | 83 | master | 1,334 | module EPUB
module ContentDocument
class XHTML
attr_accessor :item
# @param [Boolean] detect_encoding See {Publication::Package::Manifest::Item#read}
# @return [String] Returns the content string.
def read(detect_encoding: true)
item.read(detect_encoding: detect_encoding)
en... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/content_document/navigation.rb | Ruby | mit | 83 | master | 2,860 | require "epub/content_document/typable"
module EPUB
module ContentDocument
class Navigation < XHTML
include Typable
attr_accessor :navigations
def initialize
@navigations = []
@hidden = false
@parent = nil
super
end
def toc
navigations.find... |
github | KitaitiMakoto/epub-parser | https://github.com/KitaitiMakoto/epub-parser | lib/epub/content_document/typable.rb | Ruby | mit | 83 | master | 227 | require "set"
module EPUB
module ContentDocument
module Typable
def types
@types ||= Set.new
end
def types=(ts)
@types = ts.kind_of?(Set) ? ts : Set.new(ts)
end
end
end
end |
github | RyanScottLewis/service | https://github.com/RyanScottLewis/service | service.gemspec | Ruby | mit | 83 | master | 895 | Gem::Specification.new do |s|
# Variables
s.name = 'service'
s.author = 'Ryan Scott Lewis'
s.email = 'ryanscottlewis@gmail.com'
s.summary = 'A basic implementation of a Service, which has a run loop can be start and stopped or run an a new Thread.'
s.description = 'Service encapsulates... |
github | RyanScottLewis/service | https://github.com/RyanScottLewis/service | Rakefile | Ruby | mit | 83 | master | 292 | spec = eval(File.read('service.gemspec'))
require 'rake/version_task'
Rake::VersionTask.new do |t|
t.with_git_tag = true
t.with_gemspec = spec
end
require 'rubygems/package_task'
Gem::PackageTask.new(spec) do |t|
t.need_zip = false
t.need_tar = false
end
task :default => :gemspec |
github | RyanScottLewis/service | https://github.com/RyanScottLewis/service | lib/service.rb | Ruby | mit | 83 | master | 1,463 | # Service encapsulates an object which executes a bit of code in a loop that can be started or stopped and query whether
# it is running or not.
class Service
VERSION = "2.0.0".freeze
# The instance methods to be mixed into a Service.
module Base
# Query if the service is currently stopped.
#
# @re... |
github | RyanScottLewis/service | https://github.com/RyanScottLewis/service | examples/ping_pong.rb | Ruby | mit | 83 | master | 770 | require 'service'
# Generates the string "ping pong" asynchronously.
# Calls to `sleep 5` simulate computationally intensive work.
#
# Example of using the `#execute!` to execute a service in a new Thread.
# Should take ~5s (instead of ~10s)
class BaseService < Service
def initialize(buffer)
@buffer = buffer
... |
github | RyanScottLewis/service | https://github.com/RyanScottLewis/service | examples/queue.rb | Ruby | mit | 83 | master | 1,130 | require 'service'
# require 'thread' # For the Queue class
# Running two services which transfer data to each other in a thread-safe manner.
#
# Example of using the `#run!` to execute a service's run loop in a new Thread.
class BaseService < Service
def initialize(queue)
@queue = queue
end
end
# A service... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | feature_toggles.gemspec | Ruby | mit | 83 | master | 1,535 | # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "feature_toggles/version"
Gem::Specification.new do |spec|
spec.name = "feature_toggles"
spec.version = FeatureToggles::VERSION
spec.authors = ["Michael Merkushin"]
spec.email =... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | Gemfile | Ruby | mit | 83 | master | 248 | # frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in feature_toggles.gemspec
gemspec
gem "foo", path: "spec/internal/engines/foo" |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | lib/feature_toggles.rb | Ruby | mit | 83 | master | 287 | # frozen_string_literal: true
require "feature_toggles/version"
require "feature_toggles/mechatronic"
module FeatureToggles
module_function
def build(file_paths = nil, &block)
Mechatronic.new(file_paths, &block)
end
end
require "feature_toggles/railtie" if defined?(Rails) |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | lib/feature_toggles/feature.rb | Ruby | mit | 83 | master | 298 | # frozen_string_literal: true
module FeatureToggles
class Feature
def initialize(name, resolver, **metadata)
@name = name
@resolver = resolver
@metadata = metadata
end
attr_reader :name, :resolver, :metadata
def [](key)
@metadata[key]
end
end
end |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | lib/feature_toggles/railtie.rb | Ruby | mit | 83 | master | 741 | # frozen_string_literal: true
require "rails/railtie"
module Rails
class << self
delegate :features, to: "application.config"
end
end
module FeatureToggles
class Railtie < ::Rails::Railtie
config.to_prepare do
paths = []
::Rails.application.railties.each do |railtie|
next unless ra... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | lib/feature_toggles/proxy.rb | Ruby | mit | 83 | master | 445 | # frozen_string_literal: true
module FeatureToggles
class Proxy
def initialize(toggle, *args, **kwargs)
@toggle = toggle
@args = args
@kwargs = kwargs
end
def enabled?(feature)
toggle.enabled?(feature, *args, **kwargs)
end
def to_a
toggle.to_a(*args, **kwargs)
... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | lib/feature_toggles/mechatronic.rb | Ruby | mit | 83 | master | 1,637 | # frozen_string_literal: true
require_relative "proxy"
require_relative "feature"
module FeatureToggles
class Mechatronic
include Enumerable
# Which env variables should be considered truthy
POSSIBLE_ENABLING_VALUES = %w[true on yes 1].freeze
def initialize(definition_file_paths = nil, &block)
... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/spec_helper.rb | Ruby | mit | 83 | master | 442 | # frozen_string_literal: true
require "bundler/setup"
require "pry-byebug"
require "combustion"
Combustion.initialize!
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/lib/feature_toggles_spec.rb | Ruby | mit | 83 | master | 573 | # frozen_string_literal: true
RSpec.describe FeatureToggles do
it "has a version number" do
expect(FeatureToggles::VERSION).not_to be nil
end
describe ".build" do
context "by default" do
it "builds a mechatronic instance" do
expect(FeatureToggles.build).to be_a(FeatureToggles::Mechatronic)... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/lib/feature_toggles/mechatronic_spec.rb | Ruby | mit | 83 | master | 3,186 | # frozen_string_literal: true
require "tempfile"
RSpec.describe FeatureToggles::Mechatronic do
describe "definition file paths" do
let(:file_a) do
Tempfile.new("file_a").tap do |file|
file.write(<<~RUBY)
feature(:x) { false }
RUBY
file.flush
end
end
let(:f... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/lib/feature_toggles/railtie_spec.rb | Ruby | mit | 83 | master | 548 | # frozen_string_literal: true
require "feature_toggles/railtie"
RSpec.describe FeatureToggles::Railtie do
subject { Rails.features }
specify "without params", :aggregate_failures do
expect(subject.enabled?(:x)).to eq false
expect(subject.enabled?(:y)).to eq false
expect(subject.enabled?(:foo_x)).to e... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/lib/feature_toggles/feature_spec.rb | Ruby | mit | 83 | master | 648 | # frozen_string_literal: true
RSpec.describe FeatureToggles::Feature do
subject { described_class.new(name, resolver, **metadata) }
let(:name) { "some-feature" }
let(:metadata) { {foo: :bar, baz: nil} }
let(:resolver) { proc { true } }
describe "#name" do
it { expect(subject.name).to eq(name) }
end
... |
github | bibendi/feature_toggles | https://github.com/bibendi/feature_toggles | spec/internal/engines/foo/foo.gemspec | Ruby | mit | 83 | master | 1,011 | # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |spec|
spec.name = "foo"
spec.version = "0.1.0"
spec.authors = ["Michael Merkushin"]
spec.email = ["merkushin.m.s@gmail.com"]
spec.summary = "Test engine"
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.