roundtrip_xml 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/roundtrip_xml/base_cleanroom.rb +21 -4
- data/lib/roundtrip_xml/dsl_runtime.rb +6 -2
- data/lib/roundtrip_xml/root_cleanroom.rb +27 -4
- 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: 9f0012fb7fe73d2b380d6ccb789ce81e220a5cb5
|
4
|
+
data.tar.gz: b851118b3e91dd5644c77f95545621e65a98caf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d70527738c6a247d6769eca5e1b9135310b3eb1228dca18753a8d7cd9ffb51d2be3801a124431e4bd907699cd8532eb44997094d92f98c2209782fb73a211210
|
7
|
+
data.tar.gz: 77733f8c0ca731e0d1350f78fc12ca3244ae01910e63260a4a07b1fa546cc02ccbf3e72136023c6c6348f5fd4cc3cf513b5bd848151b92ad79229089ebf8e97e
|
@@ -55,20 +55,37 @@ class BaseCleanroom
|
|
55
55
|
@value_holder ||= {}
|
56
56
|
hash = plain_accessors.inject({}) {|h, a| h[a] = @el.send(a); h}
|
57
57
|
child = @runtime.create_cleanroom(clazz)
|
58
|
-
child.inherit_properties
|
58
|
+
child.inherit_properties hash.merge(@value_holder)
|
59
59
|
|
60
60
|
child.evaluate &block
|
61
|
-
|
61
|
+
new_values = child.value_holder
|
62
|
+
append_child_modifications new_values
|
63
|
+
child.get_el.process.each {|proc| child.evaluate &proc } if child.get_el.respond_to? :process
|
62
64
|
|
63
65
|
child.get_el
|
64
66
|
end
|
65
67
|
|
68
|
+
def append_child_modifications(hash)
|
69
|
+
hash.each do |k, v|
|
70
|
+
setter = "#{k}="
|
71
|
+
get_el.send(setter, v) if get_el.respond_to? setter
|
72
|
+
end
|
73
|
+
|
74
|
+
@value_holder.merge! hash
|
75
|
+
end
|
76
|
+
|
77
|
+
attr_reader :value_holder
|
66
78
|
def inherit_properties(props)
|
67
79
|
@value_holder = props
|
68
80
|
props.each do |name, val|
|
69
81
|
|
70
|
-
self.
|
71
|
-
|
82
|
+
self.instance_variable_set("@#{name}", val)
|
83
|
+
create_method name do |value = nil|
|
84
|
+
# self.instance_variable_set("@#{name}", value) if value
|
85
|
+
# instance_variable_get "@#{name}"
|
86
|
+
@value_holder[name] = value if value
|
87
|
+
@value_holder[name]
|
88
|
+
end
|
72
89
|
self.class.send(:expose, name)
|
73
90
|
end
|
74
91
|
end
|
@@ -59,9 +59,13 @@ class DslRuntime
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
def evaluate_raw(dsl, root_class)
|
62
|
+
def evaluate_raw(dsl, root_class, &block)
|
63
63
|
cleanroom = RootCleanroom.new(fetch(root_class).new, self)
|
64
|
-
|
64
|
+
if block_given?
|
65
|
+
cleanroom.evaluate &block
|
66
|
+
else
|
67
|
+
cleanroom.evaluate dsl
|
68
|
+
end
|
65
69
|
|
66
70
|
end
|
67
71
|
|
@@ -1,17 +1,40 @@
|
|
1
1
|
require 'roundtrip_xml/base_cleanroom'
|
2
|
+
require 'roundtrip_xml/utils'
|
2
3
|
# addes the `define` and `use_file` method to a cleanroom. Only used when evaluating a root file
|
3
4
|
class RootCleanroom < BaseCleanroom
|
4
|
-
|
5
|
+
include Utils
|
5
6
|
def define(name, parent, *params, &block)
|
6
|
-
|
7
|
+
parent_class = @runtime.fetch parent
|
8
|
+
new_class = new_roxml_class(name, parent_class) do
|
9
|
+
self.instance_variable_set :@class_name, name
|
7
10
|
# simply using @@params is referring to `AContainer`
|
8
|
-
self.
|
11
|
+
# hash = self.class_variable_defined?(:@@block) ? self.class_variable_get(:@@block) : {}
|
12
|
+
# hash[name] = block
|
13
|
+
self.instance_variable_set(:@block, block)
|
9
14
|
params.each do |param|
|
10
15
|
plain_accessor param
|
11
16
|
end
|
12
17
|
|
18
|
+
parent_class.plain_accessors.each do |accessor|
|
19
|
+
plain_accessor accessor
|
20
|
+
end
|
21
|
+
|
13
22
|
def process
|
14
|
-
self.class.
|
23
|
+
proc = self.class.instance_variable_get(:@block)#[self.class.instance_variable_get(:@class_name)]
|
24
|
+
if self.class.superclass.respond_to? :process
|
25
|
+
[proc].concat self.class.superclass.process
|
26
|
+
else
|
27
|
+
[proc]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def self.process
|
31
|
+
proc = self.instance_variable_get(:@block)
|
32
|
+
if self.superclass.respond_to? :process
|
33
|
+
[proc].concat self.superclass.process
|
34
|
+
else
|
35
|
+
[proc]
|
36
|
+
end
|
37
|
+
|
15
38
|
end
|
16
39
|
end
|
17
40
|
@runtime.add_class name, new_class
|