Class: PolyrexCreateObject
- Inherits:
-
Object
- Object
- PolyrexCreateObject
- Defined in:
- lib/polyrex-createobject.rb
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#parent_node ⇒ Object
Returns the value of attribute parent_node.
Instance Method Summary collapse
- #id ⇒ Object
- #id=(s) ⇒ Object
-
#initialize(schema, id: '1') ⇒ PolyrexCreateObject
constructor
A new instance of PolyrexCreateObject.
- #record=(node) ⇒ Object
Constructor Details
#initialize(schema, id: '1') ⇒ PolyrexCreateObject
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/polyrex-createobject.rb', line 16 def initialize(schema, id: '1') @@id = id raise "missing schema" unless schema @schema = schema[/\/.*$/][1..-1] a = PolyrexSchema.new(schema).to_a a.each do |rec| @obj = attach_create_handlers(rec) @obj.class_eval do def record=(node) @parent_node = node end end self.instance_eval %Q( def #{@obj.name.downcase}(h={}, id=@@id, &blk) local_schema = @schema if local_schema[0] == '{' then fields = @schema[/#{obj.name.downcase}\\[([^\\]]+)/,1].split(/\\s*,\\s*/) local_schema = "%s[%s]%s" % ['#{@obj.name.downcase}', fields.join(','), local_schema[/\\/.*$/].to_s] end new_parent = create_node(@parent_node, local_schema, h, id).element('records') obj = @obj.new obj.record = new_parent obj.instance_variable_set(:@schema, @schema[/\\/(.*$)/,1]) if block_given? then blk.call obj else obj end end ) end end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
13 14 15 |
# File 'lib/polyrex-createobject.rb', line 13 def obj @obj end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
12 13 14 |
# File 'lib/polyrex-createobject.rb', line 12 def parent_node @parent_node end |
Instance Method Details
#id ⇒ Object
62 |
# File 'lib/polyrex-createobject.rb', line 62 def id() @@id end |
#id=(s) ⇒ Object
61 |
# File 'lib/polyrex-createobject.rb', line 61 def id=(s) @@id = s; self end |
#record=(node) ⇒ Object
64 65 66 |
# File 'lib/polyrex-createobject.rb', line 64 def record=(node) @parent_node = node end |