representable 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -1,3 +1,7 @@
1
+ h2. 1.1.3
2
+
3
+ * Introduced `#compile_fragment` and friends to make it simpler overriding parsing and rendering steps.
4
+
1
5
  h2. 1.1.2
2
6
 
3
7
  * Allow `Module.hash` to be called without arguments as this seems to be required in Padrino.
data/lib/representable.rb CHANGED
@@ -45,24 +45,22 @@ module Representable
45
45
  end
46
46
 
47
47
  # Reads values from +doc+ and sets properties accordingly.
48
- def update_properties_from(doc, options, format, &block)
48
+ def update_properties_from(doc, options, format)
49
49
  representable_bindings_for(format).each do |bin|
50
50
  next if skip_property?(bin, options)
51
51
 
52
- value = bin.read(doc) || bin.definition.default
53
- send(bin.definition.setter, value)
52
+ uncompile_fragment(bin, doc)
54
53
  end
55
54
  self
56
55
  end
57
56
 
58
57
  private
59
58
  # Compiles the document going through all properties.
60
- def create_representation_with(doc, options, format, &block)
59
+ def create_representation_with(doc, options, format)
61
60
  representable_bindings_for(format).each do |bin|
62
61
  next if skip_property?(bin, options)
63
62
 
64
- value = send(bin.definition.getter) || bin.definition.default # DISCUSS: eventually move back to Ref.
65
- bin.write(doc, value) if value
63
+ compile_fragment(bin, doc)
66
64
  end
67
65
  doc
68
66
  end
@@ -74,6 +72,27 @@ private
74
72
  options[:include] ? !res : res
75
73
  end
76
74
 
75
+ # Retrieve value and write fragment to the doc.
76
+ def compile_fragment(bin, doc)
77
+ value = send(bin.definition.getter) || bin.definition.default # DISCUSS: eventually move back to Ref.
78
+ write_fragment_for(bin, value, doc)
79
+ end
80
+
81
+ # Parse value from doc and update the model property.
82
+ def uncompile_fragment(bin, doc)
83
+ value = read_fragment_for(bin, doc) || bin.definition.default
84
+ send(bin.definition.setter, value)
85
+ end
86
+
87
+ def write_fragment_for(bin, value, doc) # DISCUSS: move to Binding?
88
+ return unless value
89
+ bin.write(doc, value)
90
+ end
91
+
92
+ def read_fragment_for(bin, doc) # DISCUSS: move to Binding?
93
+ bin.read(doc)
94
+ end
95
+
77
96
  def representable_attrs
78
97
  @representable_attrs ||= self.class.representable_attrs # DISCUSS: copy, or better not?
79
98
  end
@@ -62,6 +62,7 @@ module Representable
62
62
 
63
63
  class HashBinding < JSONBinding
64
64
  def serialize_for(value)
65
+ # requires value to respond to #each with two block parameters.
65
66
  {}.tap do |hash|
66
67
  value.each { |key, obj| hash[key] = serialize(obj) }
67
68
  end
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
metadata CHANGED
@@ -1,125 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: representable
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 1
8
- - 2
9
- version: 1.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Nick Sutterer
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-03-01 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &82431430 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: json
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *82431430
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &82430990 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
44
33
  type: :runtime
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: rake
48
34
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *82430990
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &82430300 !ruby/object:Gem::Requirement
50
39
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
57
44
  type: :development
58
- version_requirements: *id003
59
- - !ruby/object:Gem::Dependency
60
- name: test_xml
61
45
  prerelease: false
62
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *82430300
47
+ - !ruby/object:Gem::Dependency
48
+ name: test_xml
49
+ requirement: &82429660 !ruby/object:Gem::Requirement
63
50
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
70
55
  type: :development
71
- version_requirements: *id004
72
- - !ruby/object:Gem::Dependency
73
- name: minitest
74
56
  prerelease: false
75
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *82429660
58
+ - !ruby/object:Gem::Dependency
59
+ name: minitest
60
+ requirement: &82426770 !ruby/object:Gem::Requirement
76
61
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- segments:
81
- - 2
82
- - 8
83
- - 1
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
84
65
  version: 2.8.1
85
66
  type: :development
86
- version_requirements: *id005
87
- - !ruby/object:Gem::Dependency
88
- name: mocha
89
67
  prerelease: false
90
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *82426770
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: &82426410 !ruby/object:Gem::Requirement
91
72
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
98
77
  type: :development
99
- version_requirements: *id006
100
- - !ruby/object:Gem::Dependency
101
- name: mongoid
102
78
  prerelease: false
103
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *82426410
80
+ - !ruby/object:Gem::Dependency
81
+ name: mongoid
82
+ requirement: &82425780 !ruby/object:Gem::Requirement
104
83
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- segments:
109
- - 0
110
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
111
88
  type: :development
112
- version_requirements: *id007
113
- description: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.
114
- email:
89
+ prerelease: false
90
+ version_requirements: *82425780
91
+ description: Maps representation documents from and to Ruby objects. Includes XML
92
+ and JSON support, plain properties, collections and compositions.
93
+ email:
115
94
  - apotonick@gmail.com
116
95
  executables: []
117
-
118
96
  extensions: []
119
-
120
97
  extra_rdoc_files: []
121
-
122
- files:
98
+ files:
123
99
  - .gitignore
124
100
  - .rspec
125
101
  - .travis.yml
@@ -150,37 +126,29 @@ files:
150
126
  - test/test_helper.rb
151
127
  - test/xml_bindings_test.rb
152
128
  - test/xml_test.rb
153
- has_rdoc: true
154
129
  homepage: http://representable.apotomo.de
155
130
  licenses: []
156
-
157
131
  post_install_message:
158
132
  rdoc_options: []
159
-
160
- require_paths:
133
+ require_paths:
161
134
  - lib
162
- required_ruby_version: !ruby/object:Gem::Requirement
135
+ required_ruby_version: !ruby/object:Gem::Requirement
163
136
  none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- segments:
168
- - 0
169
- version: "0"
170
- required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
142
  none: false
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- segments:
176
- - 0
177
- version: "0"
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
178
147
  requirements: []
179
-
180
148
  rubyforge_project:
181
- rubygems_version: 1.3.7
149
+ rubygems_version: 1.8.10
182
150
  signing_key:
183
151
  specification_version: 3
184
- summary: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.
152
+ summary: Maps representation documents from and to Ruby objects. Includes XML and
153
+ JSON support, plain properties, collections and compositions.
185
154
  test_files: []
186
-