sax_stream 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sax_stream/mapper.rb +39 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27411b80a5dfb5a158a6235b8e03d116a426f674
4
- data.tar.gz: 0ef904fee665c4858cac0c867bbe44201d945623
3
+ metadata.gz: 2128b5dc66a473ba485b767362ef8662683074ff
4
+ data.tar.gz: 64ba449057ed620532685b7a88d30ac66ade8821
5
5
  SHA512:
6
- metadata.gz: f1bd6200c50d8e463b19b696896f2c747607739e18cadb4bb02951d1c814c6bea2d6041d76a00943cb450043a55de5fd02103a15ca865db807d61f759379ef2e
7
- data.tar.gz: eb07a4aefe1a69d887546345981d8d2f336b9235fb3048f9b30bc00b09a854df1aa92ac7b30179dbf6874c42d3d8831a45613592cbb192f2053f36ba37099fc0
6
+ metadata.gz: aca2c7f39fc0185f732b60f5639fe01fdf2973828438662d3cacfe99f82cd1442cf99f1d28b829f6b60055f79754c7d5eed684a895b9a1ae8e0c3ec4764e063e
7
+ data.tar.gz: 15130ed1ca010b0981bcb97240564c8ea53795b2d0931a57da6170ef1c1ef9edfec9f3d787ba85a63301e099050c08e8a617df3a2dc8db335e7ddfec59fc8068
@@ -16,7 +16,16 @@ module SaxStream
16
16
  end
17
17
 
18
18
  def map(attribute_name, options = {})
19
- store_field_mapping(options[:to], Internal::MappingFactory.build_mapping(attribute_name, options))
19
+ store_key_for_group attribute_name
20
+ mapping = Internal::MappingFactory.build_mapping(attribute_name, options)
21
+ store_field_mapping(options[:to], mapping)
22
+ end
23
+
24
+ def attribute_group(group_name)
25
+ self.mapping_options = {group_name: group_name}
26
+ yield
27
+ ensure
28
+ clear_mapping_options
20
29
  end
21
30
 
22
31
  # Define a relation to another object which is built from an XML node using another class
@@ -107,6 +116,11 @@ module SaxStream
107
116
  @collect
108
117
  end
109
118
 
119
+ def group_keys(group_name)
120
+ @group_keys ||= {}
121
+ @group_keys[group_name] ||= []
122
+ end
123
+
110
124
  private
111
125
 
112
126
  def store_relation_mapping(key, mapping)
@@ -141,6 +155,25 @@ module SaxStream
141
155
  def parent_class_values(method_name, default)
142
156
  superclass && superclass.respond_to?(method_name) ? superclass.send(method_name) : default
143
157
  end
158
+
159
+ def mapping_options=(values)
160
+ @mapping_options = values
161
+ end
162
+
163
+ def clear_mapping_options
164
+ @mapping_options = nil
165
+ end
166
+
167
+ def with_mapping_options(input)
168
+ @mapping_options ? input.merge(@mapping_options) : input
169
+ end
170
+
171
+ def store_key_for_group(key)
172
+ group_name = (@mapping_options || {})[:group_name]
173
+ if group_name
174
+ self.group_keys(group_name) << key
175
+ end
176
+ end
144
177
  end
145
178
 
146
179
  def []=(key, value)
@@ -163,6 +196,11 @@ module SaxStream
163
196
  @attributes = value
164
197
  end
165
198
 
199
+ def group_attributes(group_name)
200
+ keys = self.class.group_keys(group_name).map(&:to_s)
201
+ attributes.reject {|key, value| !keys.include?(key) }
202
+ end
203
+
166
204
  def relations
167
205
  @relations ||= build_empty_relations
168
206
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sax_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Ambrose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri