sax_stream 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sax_stream/mapper.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49235c762a9789fcd36ed72fc59c778ca068ec86
|
4
|
+
data.tar.gz: 0cc605f5ff26e9e778d4ff4637bd74fbd2a29a96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 561128d363d81a3596e117c85376a4589156a8b374abc8c00103d5db6ef83a4205f7c5e7d74848436edbdaefae9d82f4f51b58f5e78cbb4417fcca423452db32
|
7
|
+
data.tar.gz: f12955697cc9d6aad78890e192664c8ce7ab51302a7b6ad845f4b10d2ff5ab9f344a9959ff5d50b38c69dd169115e47cf942626be54f764736e457de1aa7dc41
|
data/lib/sax_stream/mapper.rb
CHANGED
@@ -39,6 +39,8 @@ module SaxStream
|
|
39
39
|
# For relations, this can include a wildcard "*" as the last part of the path,
|
40
40
|
# eg: "product/review/*". If the path is just set to "*" then this will match
|
41
41
|
# any immediate child of the current node, which is good for polymorphic collections.
|
42
|
+
# You can also specify an array of strings to match against multiple paths, for example,
|
43
|
+
# to: ['/images/*', 'files/*', 'base_image']
|
42
44
|
# [:as] Required, no default value.
|
43
45
|
# Needs to be a class which includes SaxStream::Mapper, or an array of such classes.
|
44
46
|
# Using an array of classes, even if the array only has one item, denotes that an
|
@@ -129,10 +131,23 @@ module SaxStream
|
|
129
131
|
end
|
130
132
|
|
131
133
|
def store_field_mapping(key, mapping)
|
132
|
-
key =
|
134
|
+
key = build_key_from_array(key)
|
133
135
|
class_mappings[key] = mapping
|
134
136
|
end
|
135
137
|
|
138
|
+
def build_key_from_array(key_array)
|
139
|
+
if key_array.is_a?(Array)
|
140
|
+
joined_key = "(#{key_array.join('|')})".gsub('*', '[^/]+')
|
141
|
+
Regexp.new(joined_key)
|
142
|
+
else
|
143
|
+
build_key_regex(key_array)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def build_key_regex(key)
|
148
|
+
key.include?('*') ? Regexp.new(key.gsub('*', '[^/]+')) : key
|
149
|
+
end
|
150
|
+
|
136
151
|
def field_mapping(key)
|
137
152
|
mappings[key] || regex_field_mapping(key)
|
138
153
|
end
|