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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed71824b02e695d7398d8a74dd35186008b8b4e4
4
- data.tar.gz: 0d8cfec6b03c3ab49be2ec57fb85adb65e6e7234
3
+ metadata.gz: 9f0012fb7fe73d2b380d6ccb789ce81e220a5cb5
4
+ data.tar.gz: b851118b3e91dd5644c77f95545621e65a98caf7
5
5
  SHA512:
6
- metadata.gz: 1e4bfa899cbfa7f9aab2dd6356ebbad6704a58ce4abd3ad81f803ce3f8617c10f76dd575b8046767ddc88092f636f220ee7e43766367f7bc34321a08b05a8e4b
7
- data.tar.gz: d529ce7d02687948829b7758ab3e82ef21dd61f61948926f6730d0d9e95622cffca4b67176475c83b9407601e7d41776c06123a27c9668d5e2217da9afa88a01
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 @value_holder.merge(hash)
58
+ child.inherit_properties hash.merge(@value_holder)
59
59
 
60
60
  child.evaluate &block
61
- child.evaluate &child.get_el.process if child.get_el.respond_to? :process
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.class.send(:attr_reader, name)
71
- self.instance_variable_set("@#{name}".to_sym, val)
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
- cleanroom.evaluate dsl
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
- new_class = Class.new(@runtime.fetch parent) do
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.class_variable_set(:@@block, block)
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.class_variable_get(:@@block)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roundtrip_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Usick