Parent

Class/Module Index [+]

Quicksearch

Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflector

@private

Attributes

name[R]
subject[R]

Public Class Methods

new(subject, name) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 10
def initialize(subject, name)
  @subject = subject
  @name = name
end

Public Instance Methods

build_relation_with_clause(name, value) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 31
def build_relation_with_clause(name, value)
  case name
    when :conditions then associated_class.where(value)
    when :order      then associated_class.order(value)
    else                  raise ArgumentError, "Unknown clause '#{name}'"
  end
end
extract_relation_clause_from(relation, name) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 39
def extract_relation_clause_from(relation, name)
  case name
  when :conditions
    relation.where_values_hash
  when :order
    relation.order_values.map { |value| value_as_sql(value) }.join(', ')
  else
    raise ArgumentError, "Unknown clause '#{name}'"
  end
end
model_class() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 27
def model_class
  subject.class
end
reflect_on_association(name) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 19
def reflect_on_association(name)
  reflection = model_class.reflect_on_association(name)

  if reflection
    ModelReflection.new(reflection)
  end
end
reflection() click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 15
def reflection
  @reflection ||= reflect_on_association(name)
end

Protected Instance Methods

value_as_sql(value) click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb, line 54
def value_as_sql(value)
  if value.respond_to?(:to_sql)
    value.to_sql
  else
    value
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.