Module: EfoNelfo::HasMany

Included in:
PostType
Defined in:
lib/efo_nelfo/has_many.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/efo_nelfo/has_many.rb', line 5

def self.included(base)
  base.send :extend, ClassMethods
end

Instance Method Details

#add(post) ⇒ Object



21
22
23
# File 'lib/efo_nelfo/has_many.rb', line 21

def add(post)
  find_association(post) << post
end

#associationsObject



17
18
19
# File 'lib/efo_nelfo/has_many.rb', line 17

def associations
  self.class.associations
end

#find_association(post_type) ⇒ Object



9
10
11
# 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) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/efo_nelfo/has_many.rb', line 13

def has_association?(post_type)
  !self.class.association(post_type).nil?
end

#to_aObject



25
26
27
# File 'lib/efo_nelfo/has_many.rb', line 25

def to_a
  [ super ] + associations_array
end