class MR::FakeRecord::Attribute
Attributes
changed_method_name[R]
name[R]
null[R]
ActiveRecord methods
primary[R]
ActiveRecord methods
reader_method_name[R]
type[R]
was_method_name[R]
writer_method_name[R]
Public Class Methods
new(name, type, options = nil)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 106 def initialize(name, type, options = nil) options ||= {} @name = name.to_s @type = type.to_sym @primary = (@type == :primary_key) @null = options.key?(:null) ? !!options[:null] : true @reader_method_name = @name @writer_method_name = "#{@reader_method_name}=" @was_method_name = "#{@reader_method_name}_was" @changed_method_name = "#{@reader_method_name}_changed?" end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 141 def <=>(other) self.name <=> other.name end
==(other)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 135 def ==(other) self.name == other.name && self.type == other.type && self.null == other.null end
changed?(record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 131 def changed?(record) read(record) != was(record) end
define_on(record_class)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 145 def define_on(record_class) attribute = self record_class.class_eval do attr_accessor attribute.reader_method_name define_method(attribute.was_method_name) do attribute.was(self) end define_method(attribute.changed_method_name) do attribute.changed?(self) end end end
read(record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 119 def read(record) record.send(@reader_method_name) end
was(record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 127 def was(record) record.saved_attributes[@name] end
write(value, record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 123 def write(value, record) record.send(@writer_method_name, value) end