Class: Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflector
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflector
- Defined in:
- lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb
Instance Method Summary collapse
- #association_relation ⇒ Object
- #build_relation_with_clause(name, value) ⇒ Object
- #extract_relation_clause_from(relation, name) ⇒ Object
-
#initialize(subject, name) ⇒ ModelReflector
constructor
A new instance of ModelReflector.
- #model_class ⇒ Object
- #reflect_on_association(name) ⇒ Object
- #reflection ⇒ Object
Constructor Details
#initialize(subject, name) ⇒ ModelReflector
Returns a new instance of ModelReflector.
25 26 27 28 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 25 def initialize(subject, name) @subject = subject @name = name end |
Instance Method Details
#association_relation ⇒ Object
30 31 32 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 30 def association_relation reflection.association_relation(subject) end |
#build_relation_with_clause(name, value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 50 def build_relation_with_clause(name, value) case name when :conditions associated_class.where(value) when :order associated_class.order(value) else raise ArgumentError, "Unknown clause '#{name}'" end end |
#extract_relation_clause_from(relation, name) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 61 def extract_relation_clause_from(relation, name) case name when :conditions relation.where_values_hash when :order relation.order_values.map do |value| value_as_sql(value) end.join(', ') else raise ArgumentError, "Unknown clause '#{name}'" end end |
#model_class ⇒ Object
46 47 48 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 46 def model_class subject.class end |
#reflect_on_association(name) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 38 def reflect_on_association(name) reflection = model_class.reflect_on_association(name) if reflection ModelReflection.new(reflection) end end |
#reflection ⇒ Object
34 35 36 |
# File 'lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb', line 34 def reflection @_reflection ||= reflect_on_association(name) end |