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', order: 'ascending') ⇒ PolyrexCreateObject
constructor
A new instance of PolyrexCreateObject.
- #record=(node) ⇒ Object
Constructor Details
#initialize(schema, id: '1', order: 'ascending') ⇒ PolyrexCreateObject
Returns a new instance of 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 60 |
# File 'lib/polyrex-createobject.rb', line 16 def initialize(schema, id: '1', order: 'ascending') @@id, @order = id, order.to_s raise "missing schema" unless schema @schema = schema[/\/(.*)$/,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
63 |
# File 'lib/polyrex-createobject.rb', line 63 def id() @@id end |
#id=(s) ⇒ Object
62 |
# File 'lib/polyrex-createobject.rb', line 62 def id=(s) @@id = s; self end |
#record=(node) ⇒ Object
65 66 67 |
# File 'lib/polyrex-createobject.rb', line 65 def record=(node) @parent_node = node end |