Class: SugarCRM::Association
- Inherits:
-
Object
- Object
- SugarCRM::Association
- 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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#cardinality ⇒ Object
Returns the value of attribute cardinality.
-
#link_field ⇒ Object
Returns the value of attribute link_field.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#proxy_methods ⇒ Object
Returns the value of attribute proxy_methods.
-
#relationship ⇒ Object
Returns the value of attribute relationship.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#include?(attribute) ⇒ Boolean
Returns true if the association includes an attribute that matches the provided string.
-
#initialize(owner, link_field, opts = {}) ⇒ Association
constructor
Creates a new instance of an Association.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
- #to_s ⇒ Object
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
#attributes ⇒ Object
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/sugarcrm/associations/association.rb', line 13 def attributes @attributes end |
#cardinality ⇒ Object
Returns the value of attribute cardinality.
15 16 17 |
# File 'lib/sugarcrm/associations/association.rb', line 15 def cardinality @cardinality end |
#link_field ⇒ Object
Returns the value of attribute link_field.
11 12 13 |
# File 'lib/sugarcrm/associations/association.rb', line 11 def link_field @link_field end |
#owner ⇒ Object
Returns the value of attribute owner.
9 10 11 |
# File 'lib/sugarcrm/associations/association.rb', line 9 def owner @owner end |
#proxy_methods ⇒ Object
Returns the value of attribute proxy_methods.
14 15 16 |
# File 'lib/sugarcrm/associations/association.rb', line 14 def proxy_methods @proxy_methods end |
#relationship ⇒ Object
Returns the value of attribute relationship.
12 13 14 |
# File 'lib/sugarcrm/associations/association.rb', line 12 def relationship @relationship end |
#target ⇒ Object
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 |
#hash ⇒ Object
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
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 |
#inspect ⇒ Object
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_s ⇒ Object
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 |