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.
- checksums.yaml +4 -4
- data/lib/sax_stream/mapper.rb +39 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2128b5dc66a473ba485b767362ef8662683074ff
|
4
|
+
data.tar.gz: 64ba449057ed620532685b7a88d30ac66ade8821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca2c7f39fc0185f732b60f5639fe01fdf2973828438662d3cacfe99f82cd1442cf99f1d28b829f6b60055f79754c7d5eed684a895b9a1ae8e0c3ec4764e063e
|
7
|
+
data.tar.gz: 15130ed1ca010b0981bcb97240564c8ea53795b2d0931a57da6170ef1c1ef9edfec9f3d787ba85a63301e099050c08e8a617df3a2dc8db335e7ddfec59fc8068
|
data/lib/sax_stream/mapper.rb
CHANGED
@@ -16,7 +16,16 @@ module SaxStream
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def map(attribute_name, options = {})
|
19
|
-
|
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.
|
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-
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|