class FixedModel::Base
Public Class Methods
all()
click to toggle source
# File lib/fixed_model/base.rb, line 49 def self.all data.map { |row| new(row) } end
attribute_names()
click to toggle source
# File lib/fixed_model/base.rb, line 41 def self.attribute_names names = [] data.each do |row| names.concat(row.keys) end names.uniq.map(&:to_s) end
each(&block)
click to toggle source
# File lib/fixed_model/base.rb, line 53 def self.each(&block) all.each(&block) end
inherited(subclass)
click to toggle source
# File lib/fixed_model/base.rb, line 31 def self.inherited(subclass) subclass.define_find_by_attributes subclass.define_find_by_attributes! define_attribute_methods(subclass.attribute_names) end
new(row={})
click to toggle source
# File lib/fixed_model/base.rb, line 14 def initialize(row={}) @row = row define_attribute_readers end
Private Class Methods
data()
click to toggle source
# File lib/fixed_model/base.rb, line 121 def self.data @data ||= FixedModel::Loader.new(self).load end
define_find_by_attribute(attribute)
click to toggle source
# File lib/fixed_model/base.rb, line 91 def self.define_find_by_attribute(attribute) singleton_class.send :define_method, "find_by_#{attribute}" do |arg| row = data.find { |i| i[attribute] == arg } # or sym? row ? self.new(row) : nil end end
define_find_by_attribute!(attribute)
click to toggle source
# File lib/fixed_model/base.rb, line 98 def self.define_find_by_attribute!(attribute) singleton_class.send :define_method, "find_by_#{attribute}!" do |arg| row = data.find { |i| i[attribute] == arg } # or sym? if row self.new(row) else raise FixedModel::RecordNotFound end end end
define_find_by_attributes()
click to toggle source
# File lib/fixed_model/base.rb, line 109 def self.define_find_by_attributes attribute_names.each do |attribute| define_find_by_attribute(attribute) end end
define_find_by_attributes!()
click to toggle source
# File lib/fixed_model/base.rb, line 115 def self.define_find_by_attributes! attribute_names.each do |attribute| define_find_by_attribute!(attribute) end end
singleton_class()
click to toggle source
# File lib/fixed_model/base.rb, line 85 def self.singleton_class class << self self end end
Public Instance Methods
==(other)
click to toggle source
# File lib/fixed_model/base.rb, line 65 def ==(other) other.instance_of?(self.class) && other.attributes == attributes end
attribute?(attr)
click to toggle source
# File lib/fixed_model/base.rb, line 37 def attribute?(attr) send(attr.to_sym).present? end
attribute_names()
click to toggle source
# File lib/fixed_model/base.rb, line 57 def attribute_names @row.keys.map(&:to_s) end
attributes()
click to toggle source
# File lib/fixed_model/base.rb, line 27 def attributes @row.dup.freeze end
new_record?()
click to toggle source
# File lib/fixed_model/base.rb, line 23 def new_record? false end
persisted?()
click to toggle source
# File lib/fixed_model/base.rb, line 19 def persisted? true end
read_attribute(attribute)
click to toggle source
# File lib/fixed_model/base.rb, line 61 def read_attribute(attribute) @row[attribute] end
Private Instance Methods
attribute(attribute)
click to toggle source
Seems to be called when denmark.language is not defined and called. Look in rails source for explanation…
# File lib/fixed_model/base.rb, line 73 def attribute(attribute) nil end
define_attribute_readers()
click to toggle source
# File lib/fixed_model/base.rb, line 77 def define_attribute_readers attribute_names.each do |attribute_name| define_singleton_method attribute_name do read_attribute(attribute_name) end end end