transcriber 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Guardfile +7 -0
- data/README.md +39 -0
- data/examples/all.rb +14 -0
- data/examples/embeds_many/simple.rb +14 -0
- data/examples/embeds_many/with_class_name.rb +14 -0
- data/examples/embeds_many/with_if.rb +21 -0
- data/examples/embeds_many/with_start_key.rb +17 -0
- data/examples/embeds_one/simple.rb +14 -0
- data/examples/embeds_one/with_class_name.rb +14 -0
- data/examples/embeds_one/with_if.rb +21 -0
- data/examples/embeds_one/with_start_key.rb +14 -0
- data/examples/has_many/simple.rb +29 -0
- data/examples/properties/simple.rb +10 -0
- data/examples/properties/with_field.rb +10 -0
- data/examples/properties/with_field_path.rb +10 -0
- data/examples/properties/with_id.rb +10 -0
- data/examples/properties/with_if.rb +19 -0
- data/examples/properties/with_key_converter.rb +20 -0
- data/lib/transcriber/configuration.rb +13 -0
- data/lib/transcriber/resource/builder/embeddables.rb +21 -0
- data/lib/transcriber/resource/builder/keys.rb +20 -0
- data/lib/transcriber/resource/builder/properties.rb +29 -0
- data/lib/transcriber/resource/builder/relations.rb +26 -0
- data/lib/transcriber/resource/builder/summarizations.rb +14 -0
- data/lib/transcriber/resource/builder.rb +10 -0
- data/lib/transcriber/resource/input_path.rb +19 -0
- data/lib/transcriber/resource/key/association.rb +29 -0
- data/lib/transcriber/resource/key/embeddable.rb +8 -0
- data/lib/transcriber/resource/key/property.rb +17 -0
- data/lib/transcriber/resource/key/relation.rb +24 -0
- data/lib/transcriber/resource/key.rb +29 -0
- data/lib/transcriber/resource/parser/embeddable.rb +12 -0
- data/lib/transcriber/resource/parser/property.rb +15 -0
- data/lib/transcriber/resource/parser.rb +21 -18
- data/lib/transcriber/resource/response/embeddable.rb +14 -0
- data/lib/transcriber/resource/response/property.rb +11 -0
- data/lib/transcriber/resource/response/relation.rb +39 -0
- data/lib/transcriber/resource/response.rb +11 -0
- data/lib/transcriber/resource/serialization/boolean.rb +32 -9
- data/lib/transcriber/resource/serialization/date.rb +7 -7
- data/lib/transcriber/resource/serialization/float.rb +9 -5
- data/lib/transcriber/resource/serialization/integer.rb +13 -0
- data/lib/transcriber/resource/serialization/string.rb +7 -5
- data/lib/transcriber/resource.rb +34 -14
- data/lib/transcriber/version.rb +1 -1
- data/lib/transcriber.rb +38 -2
- data/spec/integration/has_many_spec.rb +9 -0
- data/spec/integration/property_spec.rb +0 -0
- data/spec/spec_helper.rb +22 -1
- data/spec/support/examples.rb +21 -0
- data/spec/support/out.rb +17 -0
- data/spec/unit/configuration_spec.rb +24 -0
- data/spec/unit/input_path_spec.rb +68 -0
- data/spec/unit/key_spec.rb +48 -0
- data/spec/{resource → unit}/parser_spec.rb +16 -21
- data/spec/unit/resource/builder/embeddables_spec.rb +27 -0
- data/spec/unit/resource/builder/properties_spec.rb +154 -0
- data/spec/unit/resource/builder/relations_spec.rb +54 -0
- data/spec/unit/resource/builder/shared_example_for_association.rb +20 -0
- data/spec/unit/resource/builder/summarize_spec.rb +0 -0
- data/spec/unit/resource/key/association_spec.rb +69 -0
- data/spec/unit/resource/key/embeddable_spec.rb +7 -0
- data/spec/unit/resource/key/property_spec.rb +39 -0
- data/spec/unit/resource/key/relation_spec.rb +71 -0
- data/spec/unit/resource/parser/embeddable_spec.rb +38 -0
- data/spec/unit/resource/parser/property_spec.rb +31 -0
- data/spec/unit/resource/response/embeddable_spec.rb +55 -0
- data/spec/unit/resource/response/property_spec.rb +22 -0
- data/spec/unit/resource/response/relation_spec.rb +105 -0
- data/spec/unit/resource/serialization/boolean_spec.rb +25 -0
- data/spec/unit/resource/serialization/date_spec.rb +13 -0
- data/spec/unit/resource/serialization/float_spec.rb +13 -0
- data/spec/unit/resource/serialization/integer_spec.rb +13 -0
- data/spec/unit/resource/serialization/string_spec.rb +11 -0
- data/spec/unit/resource_spec.rb +46 -0
- data/spec/unit/response_spec.rb +44 -0
- data/transcriber.gemspec +7 -3
- metadata +146 -22
- data/lib/transcriber/resource/embeddables/embeddable.rb +0 -31
- data/lib/transcriber/resource/embeddables/parser.rb +0 -10
- data/lib/transcriber/resource/embeddables/resource.rb +0 -9
- data/lib/transcriber/resource/embeddables.rb +0 -18
- data/lib/transcriber/resource/properties/parser.rb +0 -9
- data/lib/transcriber/resource/properties/property.rb +0 -30
- data/lib/transcriber/resource/properties/resource.rb +0 -7
- data/lib/transcriber/resource/properties.rb +0 -8
- data/lib/transcriber/resource/responses.rb +0 -13
- data/lib/transcriber/resource/serialization.rb +0 -10
- data/spec/resource/embeddables_spec.rb +0 -228
- data/spec/resource/properties_spec.rb +0 -69
- data/spec/resource_spec.rb +0 -27
data/.gitignore
CHANGED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Transcriber
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
gem install transciber
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
[See Examples](https://github.com/rodrigues/transcriber/tree/master/examples)
|
11
|
+
|
12
|
+
## Maintainers
|
13
|
+
|
14
|
+
* [Victor Rodrigues](http://github.com/rodrigues)
|
15
|
+
* [William "Kina"](http://github.com/kina)
|
16
|
+
* [Guilherme Guimarães Filho](http://github.com/gguimaraesbr)
|
17
|
+
|
18
|
+
## License
|
19
|
+
|
20
|
+
(The MIT License)
|
21
|
+
|
22
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
23
|
+
a copy of this software and associated documentation files (the
|
24
|
+
'Software'), to deal in the Software without restriction, including
|
25
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
26
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
27
|
+
permit persons to whom the Software is furnished to do so, subject to
|
28
|
+
the following conditions:
|
29
|
+
|
30
|
+
The above copyright notice and this permission notice shall be
|
31
|
+
included in all copies or substantial portions of the Software.
|
32
|
+
|
33
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
34
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
35
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
36
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
37
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
38
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
39
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/examples/all.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
Dir["examples/*/**.rb"].each do |file|
|
4
|
+
[:Root, :Item, :Customer, :Entry].each do |klass|
|
5
|
+
Object.send(:remove_const, klass) if Object.const_defined? klass
|
6
|
+
end
|
7
|
+
|
8
|
+
puts
|
9
|
+
puts
|
10
|
+
p "example file: #{file}"
|
11
|
+
puts
|
12
|
+
puts
|
13
|
+
load file
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Item < Transcriber::Resource
|
4
|
+
property :id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < Transcriber::Resource
|
8
|
+
embeds_many :items
|
9
|
+
end
|
10
|
+
|
11
|
+
root = Root.parse({"items" => [{"id" => 2000}]}).first
|
12
|
+
|
13
|
+
puts "root: #{root.inspect}"
|
14
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Entry < Transcriber::Resource
|
4
|
+
property :id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < Transcriber::Resource
|
8
|
+
embeds_many :items, class_name: :entry
|
9
|
+
end
|
10
|
+
|
11
|
+
root = Root.parse({"items" => [{"id" => 2000}]}).first
|
12
|
+
|
13
|
+
puts "root: #{root.inspect}"
|
14
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Item < Transcriber::Resource
|
4
|
+
property :id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < Transcriber::Resource
|
8
|
+
property :id
|
9
|
+
embeds_many :items, if: proc {id == "10"}
|
10
|
+
end
|
11
|
+
|
12
|
+
root = Root.parse({"id" => 10, "items" => [{"id" => 2000}]}).first
|
13
|
+
|
14
|
+
puts "root: #{root.inspect}"
|
15
|
+
puts "resource: #{root.resource}"
|
16
|
+
|
17
|
+
|
18
|
+
root = Root.parse({"id" => 1, "items" => [{"id" => 2000}]}).first
|
19
|
+
|
20
|
+
puts "root: #{root.inspect}"
|
21
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
$:.push 'lib'; require 'transcriber'
|
4
|
+
|
5
|
+
class Item < Transcriber::Resource
|
6
|
+
property :id, field: :item_id
|
7
|
+
end
|
8
|
+
|
9
|
+
class Root < Transcriber::Resource
|
10
|
+
embeds_many :items, start_key: 'detalhe.itens'
|
11
|
+
end
|
12
|
+
|
13
|
+
root = Root.parse({"detalhe" => {"itens" => [{"item_id" => 2000}]}}).first
|
14
|
+
|
15
|
+
puts "root: #{root.inspect}"
|
16
|
+
puts "resource: #{root.resource}"
|
17
|
+
puts "to_json: #{root.resource.to_json}"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Root < Transcriber::Resource
|
4
|
+
embeds_one :item
|
5
|
+
end
|
6
|
+
|
7
|
+
class Item < Transcriber::Resource
|
8
|
+
property :id
|
9
|
+
end
|
10
|
+
|
11
|
+
root = Root.parse({"item" => {"id" => 2000}}).first
|
12
|
+
|
13
|
+
puts "root: #{root.inspect}"
|
14
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Entry < Transcriber::Resource
|
4
|
+
property :id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < Transcriber::Resource
|
8
|
+
embeds_one :item, class_name: :entry
|
9
|
+
end
|
10
|
+
|
11
|
+
root = Root.parse({"item" => {"id" => 2000}}).first
|
12
|
+
|
13
|
+
puts "root: #{root.inspect}"
|
14
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Root < Transcriber::Resource
|
4
|
+
property :id
|
5
|
+
embeds_one :item, if: proc {id == "1"}
|
6
|
+
end
|
7
|
+
|
8
|
+
class Item < Transcriber::Resource
|
9
|
+
property :id
|
10
|
+
end
|
11
|
+
|
12
|
+
root = Root.parse({"id"=> 1, "item" => {"id" => 2000}}).first
|
13
|
+
|
14
|
+
puts "root: #{root.inspect}"
|
15
|
+
puts "resource: #{root.resource}"
|
16
|
+
|
17
|
+
|
18
|
+
root = Root.parse({"id"=> 100, "item" => {"id" => 2000}}).first
|
19
|
+
|
20
|
+
puts "root: #{root.inspect}"
|
21
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Root < Transcriber::Resource
|
4
|
+
embeds_one :item, start_key: :ugly_nesting_key
|
5
|
+
end
|
6
|
+
|
7
|
+
class Item < Transcriber::Resource
|
8
|
+
property :id
|
9
|
+
end
|
10
|
+
|
11
|
+
root = Root.parse({"ugly_nesting_key" => {"id" => 2000}}).first
|
12
|
+
|
13
|
+
puts "root: #{root.inspect}"
|
14
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Service < Transcriber::Resource
|
4
|
+
property :name
|
5
|
+
belongs_to :customer
|
6
|
+
end
|
7
|
+
|
8
|
+
class Billing < Transcriber::Resource
|
9
|
+
property :login
|
10
|
+
belongs_to :customer
|
11
|
+
end
|
12
|
+
|
13
|
+
class Developer < Transcriber::Resource
|
14
|
+
property :login
|
15
|
+
belongs_to :customer
|
16
|
+
end
|
17
|
+
|
18
|
+
class Customer < Transcriber::Resource
|
19
|
+
id field: :customer_id
|
20
|
+
property :login
|
21
|
+
has_many :services
|
22
|
+
has_one :billing
|
23
|
+
has_one :devopada, class_name: :developer
|
24
|
+
end
|
25
|
+
|
26
|
+
@root = Customer.parse({"customer_id" => 123, "login" => 2000}).first
|
27
|
+
|
28
|
+
puts "root: #{@root.inspect}"
|
29
|
+
puts "resource: #{@root.resource}"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Customer < Transcriber::Resource
|
4
|
+
property :login, field: 'hidden.login'
|
5
|
+
end
|
6
|
+
|
7
|
+
root = Customer.parse({"hidden" => {"login" => 2000}}).first
|
8
|
+
|
9
|
+
puts "root: #{root.inspect}"
|
10
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Customer < Transcriber::Resource
|
4
|
+
property :login
|
5
|
+
property :password
|
6
|
+
property :some_text, if: proc {password == "abc"}
|
7
|
+
end
|
8
|
+
|
9
|
+
root = Customer.parse({"login" => 2000, "password" => "abc", "some_text" => "some text"}).first
|
10
|
+
|
11
|
+
|
12
|
+
puts "root: #{root.inspect}"
|
13
|
+
puts "resource: #{root.resource}"
|
14
|
+
|
15
|
+
|
16
|
+
root = Customer.parse({"login" => 2000, "password" => "abcd", "some_text" => "some text II"}).first
|
17
|
+
|
18
|
+
puts "root: #{root.inspect}"
|
19
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
module Upcasing
|
4
|
+
def self.call(keys)
|
5
|
+
keys.map {|key| key.to_s.upcase}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Transcriber.configure do |c|
|
10
|
+
c.convert_input_keys = Upcasing
|
11
|
+
end
|
12
|
+
|
13
|
+
class Customer < Transcriber::Resource
|
14
|
+
property :login
|
15
|
+
end
|
16
|
+
|
17
|
+
root = Customer.parse({"LOGIN" => 2000}).first
|
18
|
+
|
19
|
+
puts "root: #{root.inspect}"
|
20
|
+
puts "resource: #{root.resource}"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Configuration
|
3
|
+
DefaultHandler = lambda {|keys| keys.map(&:to_s)}
|
4
|
+
|
5
|
+
def convert_input_keys
|
6
|
+
@convert_input_keys || DefaultHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
def convert_input_keys=(converter)
|
10
|
+
@convert_input_keys = converter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
module Builder
|
4
|
+
module Embeddables
|
5
|
+
def embeds(name, options)
|
6
|
+
key Embeddable.new(name, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def embeds_one(name, options = {})
|
10
|
+
options.merge!(many: false)
|
11
|
+
embeds(name, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def embeds_many(name, options = {})
|
15
|
+
options.merge!(many: true)
|
16
|
+
embeds(name, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
module Builder
|
4
|
+
module Keys
|
5
|
+
def key(key)
|
6
|
+
fail "you can't define a key with name '#{key.name}'" if not_allowed?(key)
|
7
|
+
attr_accessor key.name
|
8
|
+
self.keys << key
|
9
|
+
self.id_key = key if key.options[:id]
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def not_allowed?(key)
|
15
|
+
Resource.not_allowed_names.include?(key.name.to_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
module Builder
|
4
|
+
module Properties
|
5
|
+
def property(name, options = {})
|
6
|
+
key Property.new(name, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def properties(*args)
|
10
|
+
options = options(args)
|
11
|
+
names = args
|
12
|
+
names.each {|name| property(name, options)}
|
13
|
+
end
|
14
|
+
|
15
|
+
def id(*args)
|
16
|
+
options = options(args)
|
17
|
+
name = args.fetch(0, :id)
|
18
|
+
property(name, options.merge(id: true))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def options(args)
|
24
|
+
args.last.kind_of?(Hash) ? args.pop : {}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
module Builder
|
4
|
+
module Relations
|
5
|
+
def relation(name, options)
|
6
|
+
key Relation.new(name, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_one(name, options = {})
|
10
|
+
options.merge!(many: false, has: true)
|
11
|
+
relation(name, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_many(name, options = {})
|
15
|
+
options.merge!(many: true, has: true)
|
16
|
+
relation(name, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def belongs_to(name, options = {})
|
20
|
+
options.merge!(many: false, has: false)
|
21
|
+
relation(name, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
module InputPath
|
4
|
+
def self.resolve(options, convert_input_keys = Key::Converter::DefaultHandler)
|
5
|
+
convert_input_keys.call keys_for_path(custom_path(options))
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.custom_path(options)
|
11
|
+
options.slice(:start_key, :field)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.keys_for_path(path)
|
15
|
+
path.empty? ? [] : path.values.first.to_s.split('.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
class Association < Key
|
4
|
+
attr_reader :many
|
5
|
+
|
6
|
+
def initialize(name, options = {})
|
7
|
+
super
|
8
|
+
@many = options.fetch(:many, false)
|
9
|
+
@class_name = options.fetch(:class_name, default_class_name).to_s.camelize
|
10
|
+
end
|
11
|
+
|
12
|
+
def one?
|
13
|
+
!many?
|
14
|
+
end
|
15
|
+
|
16
|
+
def many?
|
17
|
+
@many
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_class_name
|
21
|
+
one? ? name : name.to_s.singularize
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource_class
|
25
|
+
@class_name.constantize
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
class Property < Key
|
4
|
+
include Parser::Property
|
5
|
+
include Response::Property
|
6
|
+
|
7
|
+
attr_accessor :serializer
|
8
|
+
attr_accessor :translations
|
9
|
+
|
10
|
+
def initialize(name, options = {})
|
11
|
+
super
|
12
|
+
@serializer = options.fetch(:type, Serialization::String)
|
13
|
+
@translations = options[:values].try(:invert)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
class Relation < Association
|
4
|
+
include Response::Relation
|
5
|
+
|
6
|
+
def initialize(name, options = {})
|
7
|
+
super
|
8
|
+
@has = options.fetch(:has, false)
|
9
|
+
end
|
10
|
+
|
11
|
+
def has?
|
12
|
+
@has
|
13
|
+
end
|
14
|
+
|
15
|
+
def belongs?
|
16
|
+
!has?
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(value)
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
class Key
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :options
|
6
|
+
attr_accessor :summarize
|
7
|
+
|
8
|
+
def initialize(name, options = {})
|
9
|
+
@name = name
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def present?(resource)
|
14
|
+
return true unless options[:if]
|
15
|
+
resource.instance_eval &options[:if]
|
16
|
+
end
|
17
|
+
|
18
|
+
def input_path
|
19
|
+
return @input_path if @input_path
|
20
|
+
path = InputPath.resolve(options, convert_input_keys)
|
21
|
+
@input_path = path.empty? ? convert_input_keys.call([name]) : path
|
22
|
+
end
|
23
|
+
|
24
|
+
def convert_input_keys
|
25
|
+
options.fetch(:convert_input_keys, Transcriber.configuration.convert_input_keys)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|