Class: PolyrexCreateObject

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrex-createobject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, id: '1') ⇒ 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
# 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
  @obj = attach_create_handlers(a[0])

  @obj.class_eval do 
    def record=(node)
      @parent_node = node
    end
  end

  self.instance_eval " def #{@obj.name.downcase}(h={}, id=@@id, &blk)

    new_parent = create_node(@parent_node, @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

Instance Attribute Details

#objObject (readonly)

Returns the value of attribute obj.



13
14
15
# File 'lib/polyrex-createobject.rb', line 13

def obj
  @obj
end

#parent_nodeObject

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

#idObject



51
# File 'lib/polyrex-createobject.rb', line 51

def id() @@id end

#id=(s) ⇒ Object



50
# File 'lib/polyrex-createobject.rb', line 50

def id=(s)  @@id = s; self end

#record=(node) ⇒ Object



53
54
55
# File 'lib/polyrex-createobject.rb', line 53

def record=(node)
  @parent_node = node
end