transcriber 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ property :name
5
+ embeds_many :phones, class_name: "Array"
6
+ end
7
+
8
+ @root = Customer.new({name: "Jackie Chan", phones: ["1391938", "893271984"]})
9
+
10
+ puts "root: #{@root.inspect}"
11
+ puts "resource: #{@root.resource}"
@@ -0,0 +1,32 @@
1
+ module Transcriber
2
+ class Resource
3
+ module InputParser
4
+ def to_input(options = {})
5
+ input = {}
6
+ keys_to_input(options).each do |key|
7
+ value = __send__("#{key.name}")
8
+ parsed_value = key.to_input(value, options.fetch(key.name, {}))
9
+ path = key.input_path
10
+
11
+ if path.any?
12
+ last = path.pop
13
+ key_input = path.inject(input) {|buffer, key| buffer[key] = {}; buffer[key]}
14
+ key_input[last] = parsed_value
15
+ else
16
+ input.merge!(parsed_value)
17
+ end
18
+ end
19
+ input.with_indifferent_access
20
+ end
21
+
22
+ private
23
+
24
+ def keys_to_input(options)
25
+ self.class.keys.clone.tap do |keys|
26
+ keys.reject! {|k| k.kind_of?(Relation)} unless options.fetch(:relations, true)
27
+ keys.reject! {|k| Array(options[:without]).include?(k.name)}
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -9,7 +9,7 @@ module Transcriber
9
9
  end
10
10
 
11
11
  def from_hash(attrs)
12
- return hash if raw?
12
+ return attrs if raw?
13
13
  super
14
14
  end
15
15
 
@@ -2,6 +2,7 @@ module Transcriber
2
2
  class Resource
3
3
  extend Builder
4
4
  extend Parser
5
+ include InputParser
5
6
  include Response
6
7
  include Serialization
7
8
 
@@ -51,32 +52,5 @@ module Transcriber
51
52
  def self.not_allowed_names
52
53
  %w(resource_id resource link)
53
54
  end
54
-
55
- def to_input(options = {})
56
- input = {}
57
- keys_to_input(options).each do |key|
58
- value = __send__("#{key.name}")
59
- parsed_value = key.to_input(value, options.fetch(key.name, {}))
60
- path = key.input_path
61
-
62
- if path.any?
63
- last = path.pop
64
- key_input = path.inject(input) {|buffer, key| buffer[key] = {}; buffer[key]}
65
- key_input[last] = parsed_value
66
- else
67
- input.merge!(parsed_value)
68
- end
69
- end
70
- input.with_indifferent_access
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
81
55
  end
82
56
  end
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
data/lib/transcriber.rb CHANGED
@@ -8,6 +8,7 @@ require 'active_support/core_ext/hash/slice'
8
8
  require "active_support/core_ext/hash/indifferent_access"
9
9
 
10
10
  require 'transcriber/resource/input_path'
11
+ require 'transcriber/resource/input_parser'
11
12
  require 'transcriber/resource/parser'
12
13
  require 'transcriber/resource/response'
13
14
  require 'transcriber/resource/serialization/boolean'
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.14
4
+ version: 0.0.15
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: &70220405743540 !ruby/object:Gem::Requirement
18
+ requirement: &70237690466580 !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: *70220405743540
26
+ version_requirements: *70237690466580
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70220405742940 !ruby/object:Gem::Requirement
29
+ requirement: &70237690466060 !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: *70220405742940
37
+ version_requirements: *70237690466060
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70220405742440 !ruby/object:Gem::Requirement
40
+ requirement: &70237690465600 !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: *70220405742440
48
+ version_requirements: *70237690465600
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70220405741980 !ruby/object:Gem::Requirement
51
+ requirement: &70237690465000 !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: *70220405741980
59
+ version_requirements: *70237690465000
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70220405741500 !ruby/object:Gem::Requirement
62
+ requirement: &70237690464520 !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: *70220405741500
70
+ version_requirements: *70237690464520
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70220405741040 !ruby/object:Gem::Requirement
73
+ requirement: &70237690463980 !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: *70220405741040
81
+ version_requirements: *70237690463980
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com
@@ -108,6 +108,7 @@ files:
108
108
  - examples/embeds_one/with_start_key.rb
109
109
  - examples/has_many/simple.rb
110
110
  - examples/initialize/embeds_many.rb
111
+ - examples/initialize/embeds_many_array.rb
111
112
  - examples/initialize/embeds_one.rb
112
113
  - examples/initialize/simple.rb
113
114
  - examples/properties/array_serialization.rb
@@ -139,6 +140,7 @@ files:
139
140
  - lib/transcriber/resource/builder/properties.rb
140
141
  - lib/transcriber/resource/builder/relations.rb
141
142
  - lib/transcriber/resource/builder/summarizations.rb
143
+ - lib/transcriber/resource/input_parser.rb
142
144
  - lib/transcriber/resource/input_path.rb
143
145
  - lib/transcriber/resource/key.rb
144
146
  - lib/transcriber/resource/key/association.rb