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 = nil, id: nil, order: 'ascending', record: nil, debug: false) ⇒ PolyrexCreateObject
constructor
A new instance of PolyrexCreateObject.
- #record=(node) ⇒ Object
Constructor Details
#initialize(schema = nil, id: nil, order: 'ascending', record: nil, debug: false) ⇒ 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 61 62 63 64 65 66 67 68 69 |
# File 'lib/polyrex-createobject.rb', line 16 def initialize(schema=nil, id: nil, order: 'ascending', record: nil, debug: false) @order = order.to_s @id = id if @debug then puts 'inside PolyrexCreateObject: record: ' + record.xml.inspect puts 'record.text' + record.text('summary/schema') end @parent_node = record ? record.element('records') : record schema = record.text('summary/schema') puts ': schema: ' + schema.inspect if @debug raise "missing schema" unless schema @schema = schema =~ /\// ? schema[/\/(.*)$/,1] : schema a = PolyrexSchema.new(schema).to_a puts 'a: ' + a.inspect if @debug a.each do |rec| @obj = attach_create_handlers(rec) puts '@obj: ' + @obj.inspect if @debug @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) if block_given? then yield(PolyrexCreateObject.new(id: id, record: new_parent)) else self 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
72 |
# File 'lib/polyrex-createobject.rb', line 72 def id() @id end |
#id=(s) ⇒ Object
71 |
# File 'lib/polyrex-createobject.rb', line 71 def id=(s) @id = s; self end |
#record=(node) ⇒ Object
74 75 76 |
# File 'lib/polyrex-createobject.rb', line 74 def record=(node) @parent_node = node end |