Class: SmartEnum::Associations::Association
- Inherits:
-
Object
- Object
- SmartEnum::Associations::Association
- Defined in:
- lib/smart_enum/associations.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#as_option ⇒ Object
readonly
Returns the value of attribute as_option.
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#class_name_option ⇒ Object
readonly
Returns the value of attribute class_name_option.
-
#foreign_key_option ⇒ Object
readonly
Returns the value of attribute foreign_key_option.
-
#owner_class ⇒ Object
readonly
Returns the value of attribute owner_class.
Instance Method Summary collapse
- #association_class ⇒ Object
- #class_name ⇒ Object
- #foreign_key ⇒ Object
- #generated_method_name ⇒ Object
-
#initialize(owner_class, association_name, class_name: nil, as: nil, foreign_key: nil) ⇒ Association
constructor
A new instance of Association.
Constructor Details
#initialize(owner_class, association_name, class_name: nil, as: nil, foreign_key: nil) ⇒ Association
Returns a new instance of Association.
101 102 103 104 105 106 107 |
# File 'lib/smart_enum/associations.rb', line 101 def initialize(owner_class, association_name, class_name: nil, as: nil, foreign_key: nil) @owner_class = owner_class @association_name = association_name.to_sym @class_name_option = class_name @as_option = as @foreign_key_option = foreign_key end |
Instance Attribute Details
#as_option ⇒ Object (readonly)
Returns the value of attribute as_option.
99 100 101 |
# File 'lib/smart_enum/associations.rb', line 99 def as_option @as_option end |
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
99 100 101 |
# File 'lib/smart_enum/associations.rb', line 99 def association_name @association_name end |
#class_name_option ⇒ Object (readonly)
Returns the value of attribute class_name_option.
99 100 101 |
# File 'lib/smart_enum/associations.rb', line 99 def class_name_option @class_name_option end |
#foreign_key_option ⇒ Object (readonly)
Returns the value of attribute foreign_key_option.
99 100 101 |
# File 'lib/smart_enum/associations.rb', line 99 def foreign_key_option @foreign_key_option end |
#owner_class ⇒ Object (readonly)
Returns the value of attribute owner_class.
99 100 101 |
# File 'lib/smart_enum/associations.rb', line 99 def owner_class @owner_class end |
Instance Method Details
#association_class ⇒ Object
121 122 123 124 125 |
# File 'lib/smart_enum/associations.rb', line 121 def association_class @association_class ||= SmartEnum::Utilities.constantize(class_name).tap{|klass| ::SmartEnum::Associations.__assert_enum(klass) } end |
#class_name ⇒ Object
109 110 111 |
# File 'lib/smart_enum/associations.rb', line 109 def class_name @class_name ||= (class_name_option || SmartEnum::Utilities.classify(association_name)).to_s end |
#foreign_key ⇒ Object
113 114 115 |
# File 'lib/smart_enum/associations.rb', line 113 def foreign_key @foreign_key ||= (foreign_key_option || SmartEnum::Utilities.foreign_key(association_name)).to_sym end |
#generated_method_name ⇒ Object
117 118 119 |
# File 'lib/smart_enum/associations.rb', line 117 def generated_method_name @generated_method_name ||= (as_option || association_name).to_sym end |