clinth3o-acdc 0.1.4 → 0.1.5
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/lib/acdc/body.rb +16 -6
- data/lib/acdc/element.rb +9 -5
- data/lib/acdc.rb +3 -3
- metadata +1 -1
data/lib/acdc/body.rb
CHANGED
@@ -38,9 +38,9 @@ module AcDc
|
|
38
38
|
else
|
39
39
|
raise ArgumentError.new("Type is invalid") unless val.is_a?(type)
|
40
40
|
end
|
41
|
-
elements.update(key => type.new(val,options_for(key)
|
41
|
+
elements.update(key => type.new(val, options_for(key)))
|
42
42
|
else
|
43
|
-
elements.update(key => Element(val,options_for(key)
|
43
|
+
elements.update(key => Element(val, options_for(key)))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -51,7 +51,7 @@ module AcDc
|
|
51
51
|
xml = Builder::XmlMarkup.new
|
52
52
|
attrs = attributes.inject({}){|acc,attr| acc.update(attr[1].to_hash)}
|
53
53
|
xml.tag!(tag_name,attrs){ |body|
|
54
|
-
elements.each do |key, elem|
|
54
|
+
elements.sort{|a,b| a[1].sequence <=> b[1].sequence}.each do |key, elem|
|
55
55
|
body << elem.acdc
|
56
56
|
end
|
57
57
|
}
|
@@ -76,17 +76,22 @@ module AcDc
|
|
76
76
|
def inherited(child)
|
77
77
|
child.instance_variable_set('@declared_elements', @declared_elements)
|
78
78
|
child.instance_variable_set('@declared_attributes', @declared_attributes)
|
79
|
+
child.instance_variable_set('@element_sequence', @element_sequence)
|
79
80
|
end
|
80
81
|
|
81
82
|
# Declare an Element for this Body
|
83
|
+
# Sequence of elements (XML Schema sequence) is taken care of by the order
|
84
|
+
# the elements are declared in the class definition.
|
82
85
|
#@param [Symbol] name A name to assign the Element (tag name)
|
83
86
|
#@param [Class] type A type to use for the element (enforcement)
|
84
87
|
#@option options [Boolean] :single False if object is a collection
|
88
|
+
#@option options [String] :tag String determining the name to use in the XML tag
|
85
89
|
def element(*options)
|
86
90
|
name = options.first
|
87
|
-
type = options.second || nil
|
91
|
+
type = options.second || nil unless options.second.is_a?(Hash)
|
88
92
|
opts = options.extract_options!
|
89
|
-
|
93
|
+
opts.merge!(:tag => name) if opts[:tag].nil?
|
94
|
+
declared_elements.update(name => opts.merge(:type => type, :sequence => next_sequence))
|
90
95
|
end
|
91
96
|
|
92
97
|
# Declare an attribute for this Body
|
@@ -137,6 +142,11 @@ module AcDc
|
|
137
142
|
klass = name.constantize
|
138
143
|
klass.new(value_from_node(node), :attributes => attrs)
|
139
144
|
end
|
145
|
+
|
146
|
+
def next_sequence
|
147
|
+
@element_sequence ||= 0
|
148
|
+
@element_sequence = @element_sequence +=1
|
149
|
+
end
|
140
150
|
end
|
141
151
|
|
142
152
|
private
|
@@ -156,7 +166,7 @@ module AcDc
|
|
156
166
|
def write(method_id, *args, &block)
|
157
167
|
key = method_id.to_s.gsub(/\=$/,"").to_sym
|
158
168
|
if elements.has_key?(key)
|
159
|
-
elements.update(key => Element(args.first,options_for(key)
|
169
|
+
elements.update(key => Element(args.first, options_for(key)))
|
160
170
|
else
|
161
171
|
attributes.update(key => Attribute(key,args.first))
|
162
172
|
end
|
data/lib/acdc/element.rb
CHANGED
@@ -8,9 +8,9 @@ module AcDc
|
|
8
8
|
# Constructor with the following:
|
9
9
|
#@param [Object] value Any value to place in the tags
|
10
10
|
#@option options [Boolean] :single False if object is a collection
|
11
|
-
#@
|
12
|
-
def initialize(value, options={}
|
13
|
-
@tag = tag ||= self.class.to_s.split("::").last
|
11
|
+
#@option options [String] :tag A tag name to use if not Element
|
12
|
+
def initialize(value, options={})
|
13
|
+
@tag = options[:tag] ||= self.class.to_s.split("::").last
|
14
14
|
@value = value
|
15
15
|
@options = options
|
16
16
|
@attributes = options.delete(:attributes)
|
@@ -33,8 +33,8 @@ module AcDc
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# The name to use for the tag
|
36
|
-
def tag_name
|
37
|
-
tag.to_s
|
36
|
+
def tag_name
|
37
|
+
tag.to_s
|
38
38
|
end
|
39
39
|
|
40
40
|
# Overridden to compare the values and not the whole object
|
@@ -44,6 +44,10 @@ module AcDc
|
|
44
44
|
value.eql?(other.value)
|
45
45
|
end
|
46
46
|
|
47
|
+
def sequence
|
48
|
+
@options[:sequence]
|
49
|
+
end
|
50
|
+
|
47
51
|
private
|
48
52
|
def tag_content
|
49
53
|
(attributes.nil? or attributes.empty?) ? tag_name : [tag_name,attributes]
|
data/lib/acdc.rb
CHANGED
@@ -9,7 +9,7 @@ require File.join(File.dirname(__FILE__),"acdc","body")
|
|
9
9
|
|
10
10
|
module AcDc
|
11
11
|
|
12
|
-
VERSION = [0,1,
|
12
|
+
VERSION = [0,1,5] unless defined?(AcDc::VERSION)
|
13
13
|
|
14
14
|
if defined?(JAIL_BREAK)
|
15
15
|
Element.class_eval{ alias :to_s :acdc }
|
@@ -19,8 +19,8 @@ module AcDc
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Will construct a AcDc::Element classs
|
22
|
-
def Element(value, options = {}
|
23
|
-
AcDc::Element.new(value,options
|
22
|
+
def Element(value, options = {})
|
23
|
+
AcDc::Element.new(value,options)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Will construct a AcDc::Attribute class
|