Module: Taketo::AssociatedNodes::InstanceMethods

Defined in:
lib/taketo/associated_nodes.rb

Instance Method Summary collapse

Instance Method Details

#find(singular_node_name, name) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/taketo/associated_nodes.rb', line 58

def find(singular_node_name, name)
  send("find_#{singular_node_name}", name) or
    if block_given?
      yield
    else
      raise KeyError, "#{singular_node_name} #{name} not found for #{qualified_name}"
    end
end

#has_deeply_nested_nodes?(name_plural) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/taketo/associated_nodes.rb', line 81

def has_deeply_nested_nodes?(name_plural)
  has_nodes?(name_plural) || self.class.node_types.any? { |n| nodes(n).any? { |node| node.has_deeply_nested_nodes?(name_plural) } }
end

#has_nodes?(name_plural) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/taketo/associated_nodes.rb', line 74

def has_nodes?(name_plural)
  unless self.class.node_types.include?(name_plural)
    raise NodesNotDefinedError, "#{name_plural} not defined for #{qualified_name}"
  end
  @nodes.fetch(name_plural) { [] }.any?
end

#initialize(*args) ⇒ Object



54
55
56
# File 'lib/taketo/associated_nodes.rb', line 54

def initialize(*args)
  @nodes = {}
end

#nodes(name_plural) ⇒ Object



67
68
69
70
71
72
# File 'lib/taketo/associated_nodes.rb', line 67

def nodes(name_plural)
  unless self.class.node_types.include?(name_plural)
    raise NodesNotDefinedError, "#{name_plural} not defined for #{qualified_name}"
  end
  @nodes[name_plural] ||= Taketo::Support::NamedNodesCollection.new
end

#qualified_nameObject

Ovverride for better error messages



87
88
89
# File 'lib/taketo/associated_nodes.rb', line 87

def qualified_name
  self.class.name
end