unhappymapper 0.4.4 → 0.5.0
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.
- data/README.md +3 -3
- data/lib/happymapper.rb +12 -12
- data/spec/happymapper_spec.rb +1 -1
- data/spec/happymapper_to_xml_spec.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -222,12 +222,12 @@ Well if we only going to parse country, on it's own, we would likely create a cl
|
|
222
222
|
tag 'country'
|
223
223
|
|
224
224
|
attribute :code, String
|
225
|
-
|
225
|
+
content :name, String
|
226
226
|
end
|
227
227
|
|
228
|
-
We are utilizing an `attribute` declaration and a new declaration called `
|
228
|
+
We are utilizing an `attribute` declaration and a new declaration called `content`.
|
229
229
|
|
230
|
-
* `
|
230
|
+
* `content` is used when you want the text contained within the element
|
231
231
|
|
232
232
|
Awesome, now if we were to redeclare our `Address` class we would use our new `Country` class.
|
233
233
|
|
data/lib/happymapper.rb
CHANGED
@@ -107,7 +107,7 @@ module HappyMapper
|
|
107
107
|
def elements
|
108
108
|
@elements[to_s] || []
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
#
|
112
112
|
# The value stored in the text node of the current element.
|
113
113
|
#
|
@@ -117,16 +117,16 @@ module HappyMapper
|
|
117
117
|
#
|
118
118
|
# # definition of the 'firstName' text node within the class
|
119
119
|
#
|
120
|
-
#
|
120
|
+
# content :first_name, String
|
121
121
|
#
|
122
122
|
# @param [Symbol] name the name of the accessor that is created
|
123
123
|
# @param [String,Class] type the class name of the name of the class whcih
|
124
124
|
# the object will be converted upon parsing
|
125
125
|
# @param [Hash] options additional parameters to send to the relationship
|
126
126
|
#
|
127
|
-
def
|
128
|
-
@
|
129
|
-
attr_accessor @
|
127
|
+
def content(name, type, options={})
|
128
|
+
@content = TextNode.new(name, type, options)
|
129
|
+
attr_accessor @content.method_name.intern
|
130
130
|
end
|
131
131
|
|
132
132
|
#
|
@@ -315,8 +315,8 @@ module HappyMapper
|
|
315
315
|
obj.send("#{elem.method_name}=",elem.from_xml_node(n, namespace, namespaces))
|
316
316
|
end
|
317
317
|
|
318
|
-
if @
|
319
|
-
obj.send("#{@
|
318
|
+
if @content
|
319
|
+
obj.send("#{@content.method_name}=",@content.from_xml_node(n, namespace, namespaces))
|
320
320
|
end
|
321
321
|
|
322
322
|
# If the HappyMapper class has the method #xml_value=,
|
@@ -481,16 +481,16 @@ module HappyMapper
|
|
481
481
|
|
482
482
|
|
483
483
|
#
|
484
|
-
# When a
|
484
|
+
# When a content has been defined we add the resulting value
|
485
485
|
# the output xml
|
486
486
|
#
|
487
|
-
if
|
487
|
+
if content = self.class.instance_variable_get('@content')
|
488
488
|
|
489
|
-
unless
|
490
|
-
text_accessor =
|
489
|
+
unless content.options[:read_only]
|
490
|
+
text_accessor = content.tag || content.name
|
491
491
|
value = send(text_accessor)
|
492
492
|
|
493
|
-
if on_save_action =
|
493
|
+
if on_save_action = content.options[:on_save]
|
494
494
|
if on_save_action.is_a?(Proc)
|
495
495
|
value = on_save_action.call(value)
|
496
496
|
elsif respond_to?(on_save_action)
|
data/spec/happymapper_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unhappymapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ date: 2011-08-22 00:00:00.000000000Z
|
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: nokogiri
|
21
|
-
requirement: &
|
21
|
+
requirement: &70125244720920 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
@@ -26,10 +26,10 @@ dependencies:
|
|
26
26
|
version: '1.4'
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
|
-
version_requirements: *
|
29
|
+
version_requirements: *70125244720920
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
|
-
requirement: &
|
32
|
+
requirement: &70125244720240 !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
version: 1.3.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
|
-
version_requirements: *
|
40
|
+
version_requirements: *70125244720240
|
41
41
|
description: Object to XML Mapping Library, using Nokogiri (fork from John Nunemaker's
|
42
42
|
Happymapper)
|
43
43
|
email: franklin.webber@gmail.com
|