class MR::FakeRecord::Reflection

Constants

ASSOCIATION_CLASS
BELONGS_TO_ASSOC_PROC

Attributes

association_class[R]
foreign_key[R]
foreign_type[R]
macro[R]

ActiveRecord methods

name[R]

ActiveRecord methods

options[R]

ActiveRecord methods

reader_method_name[R]
writer_method_name[R]

Public Class Methods

new(macro, name, options = nil) click to toggle source
# File lib/mr/fake_record/associations.rb, line 136
def initialize(macro, name, options = nil)
  @macro   = macro.to_sym
  @name    = name
  @options = options || {}

  @class_name   = @options[:class_name]
  @foreign_key  = @options[:foreign_key]
  @foreign_type = @options[:foreign_type]

  @reader_method_name = name.to_s
  @writer_method_name = "#{@reader_method_name}="
  @association_class  = ASSOCIATION_CLASS[@macro].call(self)
end

Public Instance Methods

<=>(other) click to toggle source
Calls superclass method
# File lib/mr/fake_record/associations.rb, line 169
def <=>(other)
  if other.kind_of?(self.class)
    [ self.macro,  self.options[:polymorphic],  self.name ].map(&:to_s) <=>
    [ other.macro, other.options[:polymorphic], other.name ].map(&:to_s)
  else
    super
  end
end
define_accessor_on(fake_record_class) click to toggle source
# File lib/mr/fake_record/associations.rb, line 155
def define_accessor_on(fake_record_class)
  reflection = self
  fake_record_class.class_eval do

    define_method(reflection.reader_method_name) do
      self.association(reflection.name).read
    end
    define_method(reflection.writer_method_name) do |value|
      self.association(reflection.name).write(value)
    end

  end
end
klass() click to toggle source

ActiveRecord method

# File lib/mr/fake_record/associations.rb, line 151
def klass
  @klass ||= (@class_name.to_s.constantize if @class_name)
end