transcriber 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ properties :login, :name
5
+ embeds_many :phones
6
+ end
7
+
8
+ class Phone < Transcriber::Resource
9
+ properties :number, :extension, :description
10
+ end
11
+
12
+ @root = Customer.new({
13
+ login: 'jackiechan2010',
14
+ name: "Jackie Chan",
15
+ phones: [
16
+ {
17
+ number: "897289472",
18
+ extension: "3897",
19
+ description: "abab"
20
+ },
21
+ {
22
+ number: "987198732",
23
+ extension: "1897",
24
+ description: "eheh"
25
+ }
26
+ ]
27
+ })
28
+
29
+ puts "root.to_input: #{@root.to_input(phones: {without: :description})}"
30
+ puts "root: #{@root.inspect}"
@@ -0,0 +1,23 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ properties :login, :name
5
+ embeds_one :address
6
+ end
7
+
8
+ class Address < Transcriber::Resource
9
+ properties :street, :number, :hint
10
+ end
11
+
12
+ @root = Customer.new({
13
+ login: 'jackiechan2010',
14
+ name: "Jackie Chan",
15
+ address: {
16
+ street: "Aurora St",
17
+ number: 1833,
18
+ hint: "near gas station"
19
+ }
20
+ })
21
+
22
+ puts "root.to_input: #{@root.to_input(address: {without: :hint})}"
23
+ puts "root: #{@root.inspect}"
@@ -0,0 +1,11 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ property :login
5
+ property :name
6
+ end
7
+
8
+ @root = Customer.new(login: 'jackiechan2010', name: "Jackie Chan")
9
+
10
+ puts "root.to_input: #{@root.to_input(without: :name)}"
11
+ puts "root: #{@root.inspect}"
@@ -0,0 +1,11 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ property :login
5
+ has_one :service
6
+ end
7
+
8
+ @root = Customer.new(login: 'jackiechan2010')
9
+
10
+ puts "root.to_input: #{@root.to_input(relations: false)}"
11
+ puts "root: #{@root.inspect}"
@@ -2,7 +2,7 @@ module Transcriber
2
2
  class Resource
3
3
  module Builder
4
4
  module Embeddables
5
- def embeds(name, options)
5
+ def embeds(name, options = {})
6
6
  key Embeddable.new(name, options)
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Transcriber
2
2
  class Resource
3
3
  module Builder
4
4
  module Relations
5
- def relation(name, options)
5
+ def relation(name, options = {})
6
6
  key Relation.new(name, options)
7
7
  end
8
8
 
@@ -31,9 +31,9 @@ module Transcriber
31
31
  : Array(attrs).map {|item| resource_class.new(item)}
32
32
  end
33
33
 
34
- def to_input(value)
34
+ def to_input(value, options = {})
35
35
  return nil if value.nil?
36
- one? ? value.to_input : value.map(&:to_input)
36
+ one? ? value.to_input(options) : value.map {|item| item.to_input(options)}
37
37
  end
38
38
  end
39
39
  end
@@ -13,7 +13,7 @@ module Transcriber
13
13
  super
14
14
  end
15
15
 
16
- def to_input(value)
16
+ def to_input(value, options = {})
17
17
  return value if raw?
18
18
  super
19
19
  end
@@ -18,7 +18,7 @@ module Transcriber
18
18
  value
19
19
  end
20
20
 
21
- def to_input(value)
21
+ def to_input(value, options = {})
22
22
  value
23
23
  end
24
24
  end
@@ -52,11 +52,11 @@ module Transcriber
52
52
  %w(resource_id resource link)
53
53
  end
54
54
 
55
- def to_input
55
+ def to_input(options = {})
56
56
  input = {}
57
- self.class.keys.each do |key|
57
+ keys_to_input(options).each do |key|
58
58
  value = __send__("#{key.name}")
59
- parsed_value = key.to_input(value)
59
+ parsed_value = key.to_input(value, options.fetch(key.name, {}))
60
60
  path = key.input_path
61
61
 
62
62
  if path.any?
@@ -69,5 +69,14 @@ module Transcriber
69
69
  end
70
70
  input.with_indifferent_access
71
71
  end
72
+
73
+ private
74
+
75
+ def keys_to_input(options)
76
+ self.class.keys.clone.tap do |keys|
77
+ keys.reject! {|k| k.kind_of?(Relation)} unless options.fetch(:relations, true)
78
+ keys.reject! {|k| Array(options[:without]).include?(k.name)}
79
+ end
80
+ end
72
81
  end
73
82
  end
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transcriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-08-30 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70278505129300 !ruby/object:Gem::Requirement
18
+ requirement: &70220405743540 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70278505129300
26
+ version_requirements: *70220405743540
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70278505128460 !ruby/object:Gem::Requirement
29
+ requirement: &70220405742940 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0.5'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70278505128460
37
+ version_requirements: *70220405742940
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70278505126920 !ruby/object:Gem::Requirement
40
+ requirement: &70220405742440 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '2.6'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70278505126920
48
+ version_requirements: *70220405742440
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70278505125200 !ruby/object:Gem::Requirement
51
+ requirement: &70220405741980 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0.5'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70278505125200
59
+ version_requirements: *70220405741980
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70278505123760 !ruby/object:Gem::Requirement
62
+ requirement: &70220405741500 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0.4'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70278505123760
70
+ version_requirements: *70220405741500
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70278505123180 !ruby/object:Gem::Requirement
73
+ requirement: &70220405741040 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: '1.0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70278505123180
81
+ version_requirements: *70220405741040
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com
@@ -121,11 +121,15 @@ files:
121
121
  - examples/properties/with_two_key_converters.rb
122
122
  - examples/summarization/simple.rb
123
123
  - examples/to_input/embeds_many.rb
124
+ - examples/to_input/embeds_many_without_key.rb
124
125
  - examples/to_input/embeds_one.rb
126
+ - examples/to_input/embeds_one_without_key.rb
125
127
  - examples/to_input/flattened.rb
126
128
  - examples/to_input/simple.rb
127
129
  - examples/to_input/with_field.rb
128
130
  - examples/to_input/with_field_path.rb
131
+ - examples/to_input/without_key.rb
132
+ - examples/to_input/without_relations.rb
129
133
  - lib/transcriber.rb
130
134
  - lib/transcriber/configuration.rb
131
135
  - lib/transcriber/resource.rb