module Taketo::AssociatedNodes::ClassMethods
Public Instance Methods
has_nodes(name_plural, name_singular)
click to toggle source
Adds nodes collections to the construct
Example:
class Bar < BaseConstruct
has_nodes :foos, :foo
end
bar = Bar.new bar.foos # => foos collection bar.append_foo(foo) # adds node the collection bar.find_foo(:foo_name) # find foo in foos collection by name
# File lib/taketo/associated_nodes.rb, line 26 def has_nodes(name_plural, name_singular) self.node_types << name_plural includable = Module.new do define_method "append_#{name_singular}" do |object| nodes(name_plural) << object end define_method "find_#{name_singular}" do |name| nodes(name_plural).find_by_name(name) end define_method name_plural do nodes(name_plural) end define_method "has_#{name_plural}?" do nodes(name_plural).any? end end self.send(:include, includable) end
node_types()
click to toggle source
# File lib/taketo/associated_nodes.rb, line 48 def node_types @node_types ||= [] end