Module: Juniter::HasChildren::ClassMethods

Defined in:
lib/juniter/has_children.rb

Instance Method Summary collapse

Instance Method Details

#array_childrenObject



45
46
47
# File 'lib/juniter/has_children.rb', line 45

def array_children
  @__array_children ||= []
end

#child(name, as: nil, array: false, map: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/juniter/has_children.rb', line 9

def child(name, as: nil, array: false, map: nil)
  child_types << name
  child_aliases[name] = as unless as.nil?
  child_processors[name] = map || ->(node) { node.text }
  array_children << name if array

  define_method :"#{name}" do
    instance_variable_set(:"@_#{name}", array ? [] : nil ) unless instance_variable_defined?(:"@_#{name}")
    instance_variable_get(:"@_#{name}")
  end

  define_method :"#{name}=" do |value|
    instance_variable_set :"@_#{name}", value
  end
end

#child_aliasesObject



41
42
43
# File 'lib/juniter/has_children.rb', line 41

def child_aliases
  @__child_aliases ||= {}
end

#child_processorsObject



37
38
39
# File 'lib/juniter/has_children.rb', line 37

def child_processors
  @__child_processors ||= {}
end

#child_typesObject



33
34
35
# File 'lib/juniter/has_children.rb', line 33

def child_types
  @__child_types ||= []
end

#text_child(*args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/juniter/has_children.rb', line 25

def text_child(*args)
  if args.any?
    @__text_child = args.first
    child(args.first)
  end
  @__text_child
end