Module: CapsuleCRM::Associations::ClassMethods

Defined in:
lib/capsule_crm/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_associationsObject

Public: Get all the belongs to associations defined on the class

Returns a Hash



27
28
29
# File 'lib/capsule_crm/associations.rb', line 27

def belongs_to_associations
  select_associations(:belongs_to)
end

#embedded_associationsObject

Public: Get all the embedded has many associations defined on the class



32
33
34
35
36
# File 'lib/capsule_crm/associations.rb', line 32

def embedded_associations
  has_many_associations.select do |name, association|
    association.embedded
  end
end

#has_many_associationsObject

Public: Gets all the has many associations defined on the class

Returns a Hash



20
21
22
# File 'lib/capsule_crm/associations.rb', line 20

def has_many_associations
  select_associations(:has_many)
end

#select_associations(macro) ⇒ Object



38
39
40
41
42
43
# File 'lib/capsule_crm/associations.rb', line 38

def select_associations(macro)
  associations.select do |name, association|
    association.macro == macro &&
      [self, self.ancestors].flatten.include?(association.defined_on)
  end
end