class IB::Model
Base
class for tableless IB
data Models, extends ActiveModel API
Public Class Methods
attr_accessible(*args)
click to toggle source
# File lib/ib/base.rb, line 63 def self.attr_accessible *args end
attr_protected(*args)
click to toggle source
Noop methods mocking ActiveRecord::Base macros
# File lib/ib/base.rb, line 60 def self.attr_protected *args end
belongs_to(model, *args)
click to toggle source
ActiveRecord::Base association API mocks
# File lib/ib/base.rb, line 68 def self.belongs_to model, *args attr_accessor model end
find(*args)
click to toggle source
# File lib/ib/base.rb, line 85 def self.find *args [] end
has_many(models, *args)
click to toggle source
# File lib/ib/base.rb, line 76 def self.has_many models, *args attr_accessor models define_method(models) do self.instance_variable_get("@#{models}") || self.instance_variable_set("@#{models}", []) end end
has_one(model, *args)
click to toggle source
# File lib/ib/base.rb, line 72 def self.has_one model, *args attr_accessor model end
new(attributes={})
click to toggle source
If a opts hash is given, keys are taken as attribute names, values as data. The model instance fields are then set automatically from the opts Hash.
# File lib/ib/base.rb, line 16 def initialize attributes={}, opts={} run_callbacks :initialize do error "Argument must be a Hash", :args unless attributes.is_a?(Hash) self.attributes = attributes # set_attribute_defaults is now after_init callback end end
serialize(*properties)
click to toggle source
ActiveRecord::Base misc
# File lib/ib/base.rb, line 95 def self.serialize *properties end
Public Instance Methods
[](key)
click to toggle source
ActiveModel-style read/write_attribute accessors
# File lib/ib/base.rb, line 35 def [] key attributes[key.to_sym] end
[]=(key, val)
click to toggle source
# File lib/ib/base.rb, line 39 def []= key, val # p key, val attributes[key.to_sym] = val end
attributes()
click to toggle source
ActiveModel API (for serialization)
# File lib/ib/base.rb, line 26 def attributes @attributes ||= HashWithIndifferentAccess.new end
attributes=(attrs)
click to toggle source
# File lib/ib/base.rb, line 30 def attributes= attrs attrs.keys.each { |key| self.send("#{key}=", attrs[key]) } end
new_record?()
click to toggle source
# File lib/ib/base.rb, line 48 def new_record? true end
save()
click to toggle source
# File lib/ib/base.rb, line 52 def save valid? end
Also aliased as: save!
to_model()
click to toggle source
# File lib/ib/base.rb, line 44 def to_model self end