class MR::FakeRecord::AttributeSet
Public Class Methods
new()
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 64 def initialize @attributes = {} end
Public Instance Methods
add(record_class, name, type, options = nil)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 90 def add(record_class, name, type, options = nil) attribute = Attribute.new(name, type, options) attribute.define_on(record_class) @attributes[name.to_s] = attribute end
batch_write(new_attributes, record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 82 def batch_write(new_attributes, record) new_attributes.each{ |name, value| find(name).write(value, record) } end
each(&block)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 72 def each(&block) @attributes.values.each(&block) end
find(name)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 68 def find(name) @attributes[name.to_s] || raise(NoAttributeError.new(name)) end
read_all(record)
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 76 def read_all(record) @attributes.values.inject({}) do |h, attribute| h.merge(attribute.name => attribute.read(record)) end end
to_a()
click to toggle source
# File lib/mr/fake_record/attributes.rb, line 86 def to_a @attributes.values.sort end