Class: RailsBestPractices::Core::ModelAssociations

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_best_practices/core/model_associations.rb

Instance Method Summary collapse

Constructor Details

#initializeModelAssociations

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_meta, association_class=nil)
  @associations[model_name] ||= {}
  @associations[model_name][association_name] = {:meta => association_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

Returns:

  • (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