class MR::FakeRecord::ReflectionSet

Public Class Methods

new() click to toggle source
# File lib/mr/fake_record/associations.rb, line 64
def initialize
  @belongs_to = {}
  @has_one  = {}
  @has_many = {}
end

Public Instance Methods

add_belongs_to(fake_record_class, name, options = nil) click to toggle source
# File lib/mr/fake_record/associations.rb, line 95
def add_belongs_to(fake_record_class, name, options = nil)
  options ||= {}
  options[:foreign_key] ||= "#{name}_id"
  if options[:polymorphic]
    options[:foreign_type] ||= "#{name}_type"
  end
  reflection = Reflection.new(:belongs_to, name, options)
  reflection.define_accessor_on(fake_record_class)
  @belongs_to[name.to_s] = reflection
end
add_has_many(fake_record_class, name, options = nil) click to toggle source
# File lib/mr/fake_record/associations.rb, line 112
def add_has_many(fake_record_class, name, options = nil)
  reflection = Reflection.new(:has_many, name, options)
  reflection.define_accessor_on(fake_record_class)
  @has_many[name.to_s] = reflection
end
add_has_one(fake_record_class, name, options = nil) click to toggle source
# File lib/mr/fake_record/associations.rb, line 106
def add_has_one(fake_record_class, name, options = nil)
  reflection = Reflection.new(:has_one, name, options)
  reflection.define_accessor_on(fake_record_class)
  @has_one[name.to_s] = reflection
end
all(type = nil) click to toggle source
# File lib/mr/fake_record/associations.rb, line 86
def all(type = nil)
  case type
  when :belongs_to, :has_one, :has_many
    self.send(type)
  else
    self.belongs_to + self.has_one + self.has_many
  end
end
belongs_to() click to toggle source
# File lib/mr/fake_record/associations.rb, line 70
def belongs_to
  @belongs_to.values.sort
end
find(name) click to toggle source
# File lib/mr/fake_record/associations.rb, line 82
def find(name)
  @belongs_to[name.to_s] || @has_one[name.to_s] || @has_many[name.to_s]
end
has_many() click to toggle source
# File lib/mr/fake_record/associations.rb, line 78
def has_many
  @has_many.values.sort
end
has_one() click to toggle source
# File lib/mr/fake_record/associations.rb, line 74
def has_one
  @has_one.values.sort
end