Class: Stratagem::Instrumentation::Models::Association
- Defined in:
- lib/stratagem/instrumentation/models/association.rb
Instance Attribute Summary collapse
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#from_class ⇒ Object
readonly
Returns the value of attribute from_class.
-
#macro ⇒ Object
readonly
Returns the value of attribute macro.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(from_class, name, foreign_key, klass, macro, options) ⇒ Association
constructor
A new instance of Association.
- #klass ⇒ Object
Constructor Details
#initialize(from_class, name, foreign_key, klass, macro, options) ⇒ Association
Returns a new instance of Association.
5 6 7 8 9 10 11 12 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 5 def initialize(from_class, name, foreign_key, klass, macro, ) @from_class = from_class @name = name @foreign_key = foreign_key @klass = klass @macro = macro @options = end |
Instance Attribute Details
#foreign_key ⇒ Object (readonly)
Returns the value of attribute foreign_key.
3 4 5 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 3 def foreign_key @foreign_key end |
#from_class ⇒ Object (readonly)
Returns the value of attribute from_class.
3 4 5 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 3 def from_class @from_class end |
#macro ⇒ Object (readonly)
Returns the value of attribute macro.
3 4 5 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 3 def macro @macro end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 3 def @options end |
Instance Method Details
#klass ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stratagem/instrumentation/models/association.rb', line 14 def klass if (@klass.kind_of?(String)) if ([:polymorphic]) @poly_count ||= 0 # all possibilities possible_classes = ActiveRecord::Base.sg_subclasses.sort {|a,b| a.name <=> b.name }.select do |sc| sc.stratagem.relations(:has_many).find {|r| r.klass == from_class } != nil end if (possible_classes.size > 0) @poly_count += 1 @poly_count = 1 if @poly_count > possible_classes.size return possible_classes[@poly_count-1] else return nil end else # unknown why the class could not be loaded return nil end else return @klass end end |