Module: XamplGenerator::ElementsAsChild

Defined in:
lib/xamplr-gen/xampl-hand-generated.rb

Instance Method Summary collapse

Instance Method Details

#add_elements(elements) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 27

def add_elements(elements)
  accessed
  index = elements.get_the_index
  if (nil == index) then
    throw "no value for the index 'pid' of elements defined in : " << elements.pp_xml
  end

  existing = @elements_child[index]

  self.remove_elements(index) if existing and (existing != elements)

  @children << elements
  @elements_child[index] = elements

  elements.add_parent(self)

  changed
  return elements
end

#elements_childObject Also known as: elements



10
11
12
13
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 10

def elements_child
  accessed
  @elements_child
end

#elements_child=(v) ⇒ Object Also known as: elements=



15
16
17
18
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 15

def elements_child=(v)
  accessed
  @elements_child = v
end

#ensure_elements(index) {|elements| ... } ⇒ Object

Yields:



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 58

def ensure_elements(index)
  accessed

  elements = @elements_child[index]
  return elements if elements

  elements = Elements.lookup(index) if Xampl.persister and Xampl.persister.automatic
  elements = Elements.new(index) unless elements

  yield(elements) if block_given?
  return add_elements(elements)
end

#init_elements_as_childObject



23
24
25
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 23

def init_elements_as_child
  @elements_child = IndexedArray.new
end

#new_elements(index) {|elements| ... } ⇒ Object

Yields:



47
48
49
50
51
52
53
54
55
56
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 47

def new_elements(index)
  accessed

  elements = nil
  elements = Elements.lookup(index) if Xampl.persister and Xampl.persister.automatic
  elements = Elements.new(index) unless elements

  yield(elements) if block_given?
  return add_elements(elements)
end

#remove_elements(index) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/xamplr-gen/xampl-hand-generated.rb', line 71

def remove_elements(index)
  accessed
  changed
  unless String === index or Symbol === index then
    index = index.get_the_index
  end
  elements = @elements_child.delete(index) if index
  @children.delete(elements)
end