module EfoNelfo::HasMany

Public Class Methods

included(base) click to toggle source
# File lib/efo_nelfo/has_many.rb, line 5
def self.included(base)
  base.send :extend, ClassMethods
end

Public Instance Methods

add(post) click to toggle source
# File lib/efo_nelfo/has_many.rb, line 21
def add(post)
  find_association(post) << post
end
associations() click to toggle source
# File lib/efo_nelfo/has_many.rb, line 17
def associations
  self.class.associations
end
find_association(post_type) click to toggle source
# File lib/efo_nelfo/has_many.rb, line 9
def find_association(post_type)
  send self.class.association(post_type) if has_association?(post_type)
end
has_association?(post_type) click to toggle source
# File lib/efo_nelfo/has_many.rb, line 13
def has_association?(post_type)
  !self.class.association(post_type).nil?
end
to_a() click to toggle source
Calls superclass method
# File lib/efo_nelfo/has_many.rb, line 25
def to_a
  [ super ] + associations_array
end

Protected Instance Methods

associations_array() click to toggle source
# File lib/efo_nelfo/has_many.rb, line 31
def associations_array
  if associations
    associations.keys.map { |name| find_association(name).to_a }.reject(&:empty?).flatten(1)
  else
    []
  end
end