Class: RailsBestPractices::Core::ModelAssociations
- Inherits:
-
Object
- Object
- RailsBestPractices::Core::ModelAssociations
- Defined in:
- lib/rails_best_practices/core/model_associations.rb
Instance Method Summary collapse
- #add_association(model_name, association_name, association_meta, association_class = nil) ⇒ Object
- #get_association(model_name, association_name) ⇒ Object
-
#initialize ⇒ ModelAssociations
constructor
A new instance of ModelAssociations.
- #is_association?(model_name, association_name) ⇒ Boolean
Constructor Details
#initialize ⇒ ModelAssociations
Returns a new instance of ModelAssociations.
5 6 7 |
# File 'lib/rails_best_practices/core/model_associations.rb', line 5 def initialize @associations = {} end |
Instance Method Details
#add_association(model_name, association_name, association_meta, association_class = nil) ⇒ Object
9 10 11 12 |
# File 'lib/rails_best_practices/core/model_associations.rb', line 9 def add_association(model_name, association_name, , association_class=nil) @associations[model_name] ||= {} @associations[model_name][association_name] = {:meta => , :class_name => association_class || association_name.classify} end |
#get_association(model_name, association_name) ⇒ Object
14 15 16 17 |
# File 'lib/rails_best_practices/core/model_associations.rb', line 14 def get_association(model_name, association_name) associations = @associations[model_name] associations and associations[association_name] end |
#is_association?(model_name, association_name) ⇒ Boolean
19 20 21 22 |
# File 'lib/rails_best_practices/core/model_associations.rb', line 19 def is_association?(model_name, association_name) associations = @associations[model_name] associations && associations[association_name] end |