Class: SugarCRM::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarcrm/associations/association.rb

Overview

Associations are middlemen between the object that holds the association, known as the @owner, and the actual associated object, known as the @target. Methods are added to the @owner that allow access to the association collection, and are held in @proxy_methods. The cardinality of the association is available in @cardinality, and the actual relationship details are held in @relationship.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, link_field, opts = {}) ⇒ Association

Creates a new instance of an Association



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sugarcrm/associations/association.rb', line 18

def initialize(owner,link_field,opts={})
  @options = { :define_methods? => true }.merge! opts
  @owner = owner
  check_valid_owner
  @link_field = link_field
  @attributes = owner.link_fields[link_field]
  @relationship = relationship_for(@attributes["relationship"])
  @target = resolve_target
  @proxy_methods = define_methods if @options[:define_methods?]
  @cardinality = resolve_cardinality
  self
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



13
14
15
# File 'lib/sugarcrm/associations/association.rb', line 13

def attributes
  @attributes
end

#cardinalityObject

Returns the value of attribute cardinality.



15
16
17
# File 'lib/sugarcrm/associations/association.rb', line 15

def cardinality
  @cardinality
end

Returns the value of attribute link_field.



11
12
13
# File 'lib/sugarcrm/associations/association.rb', line 11

def link_field
  @link_field
end

#ownerObject

Returns the value of attribute owner.



9
10
11
# File 'lib/sugarcrm/associations/association.rb', line 9

def owner
  @owner
end

#proxy_methodsObject

Returns the value of attribute proxy_methods.



14
15
16
# File 'lib/sugarcrm/associations/association.rb', line 14

def proxy_methods
  @proxy_methods
end

#relationshipObject

Returns the value of attribute relationship.



12
13
14
# File 'lib/sugarcrm/associations/association.rb', line 12

def relationship
  @relationship
end

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/sugarcrm/associations/association.rb', line 10

def target
  @target
end

Instance Method Details

#==(comparison_object) ⇒ Object Also known as: eql?



40
41
42
43
44
# File 'lib/sugarcrm/associations/association.rb', line 40

def ==(comparison_object)
  comparison_object.instance_of?(self.class) &&
  @target.class == comparison_object.class &&
  @link_field == comparison_object.link_field
end

#hashObject



47
48
49
# File 'lib/sugarcrm/associations/association.rb', line 47

def hash
  "#{@target.class}##{@link_field}".hash
end

#include?(attribute) ⇒ Boolean

Returns true if the association includes an attribute that matches the provided string

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/sugarcrm/associations/association.rb', line 33

def include?(attribute)
  return true if attribute.class == @target
  return true if attribute == link_field
  return true if methods.include? attribute
  false
end

#inspectObject



51
52
53
# File 'lib/sugarcrm/associations/association.rb', line 51

def inspect
  self
end

#pretty_print(pp) ⇒ Object



61
62
63
# File 'lib/sugarcrm/associations/association.rb', line 61

def pretty_print(pp)
  pp.text self.inspect, 0
end

#to_sObject



55
56
57
58
59
# File 'lib/sugarcrm/associations/association.rb', line 55

def to_s
  "#<#{@owner.class.session.namespace_const}::Association @proxy_methods=[#{@proxy_methods.join(", ")}], " +
  "@link_field=\"#{@link_field}\", @target=#{@target}, @owner=#{@owner.class}, " +
  "@cardinality=:#{@cardinality}>"
end