# File lib/reactive_record/active_record/instance_methods.rb, line 35 def primary_key self.class.primary_key end
module ActiveRecord::InstanceMethods
Attributes
backing_record[R]
Public Class Methods
new(hash = {})
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 11 def initialize(hash = {}) if hash.is_a? ReactiveRecord::Base @backing_record = hash else # standard active_record new -> creates a new instance, primary key is ignored if present # we have to build the backing record first then initialize it so associations work correctly @backing_record = ReactiveRecord::Base.new(self.class, {}, self) @backing_record.instance_eval do h = Hash.new hash.each { |a, v| h[a] = convert(a, v).itself } self.class.load_data do h.each do |attribute, value| unless attribute == primary_key reactive_set!(attribute, value) changed_attributes << attribute end end #changed_attributes << primary_key # insures that changed attributes has at least one element end end end end
Public Instance Methods
==(ar_instance)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 72 def ==(ar_instance) @backing_record == ar_instance.instance_eval { @backing_record } end
[](attr)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 76 def [](attr) send(attr) end
[]=(attr, val)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 80 def []=(attr, val) send("#{attr}=", val) end
attributes()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 7 def attributes @backing_record.attributes end
changed?()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 64 def changed? @backing_record.changed? end
destroy(&block)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 133 def destroy(&block) @backing_record.destroy &block end
destroyed?()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 137 def destroyed? @backing_record.destroyed end
dup()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 68 def dup self.class.new(self.attributes) end
errors()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 145 def errors React::State.get_state(@backing_record, @backing_record) @backing_record.errors end
id()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 47 def id @backing_record.reactive_get!(primary_key) end
id=(value)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 51 def id=(value) @backing_record.id = value end
itself()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 108 def itself # this is useful when you just want to get a handle on record instance # in the ReactiveRecord.load method id # force load of id... self end
load(*attributes) { |*results| ... }
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 115 def load(*attributes, &block) first_time = true ReactiveRecord.load do results = attributes.collect { |attr| @backing_record.reactive_get!(attr, first_time) } results = yield *results if block first_time = false block.nil? && results.count == 1 ? results.first : results end end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/reactive_record/active_record/instance_methods.rb, line 88 def method_missing(name, *args, &block) method_missing_warning("#{name}(#{args})") if name =~ /\!$/ name = name.gsub(/\!$/,"") force_update = true end if name =~ /_changed\?$/ @backing_record.changed?(name.gsub(/_changed\?$/,"")) elsif args.count == 1 && name =~ /=$/ && !block attribute_name = name.gsub(/=$/,"") @backing_record.reactive_set!(attribute_name, backing_record.convert(attribute_name, args[0])) elsif args.count.zero? && !block @backing_record.reactive_get!(name, force_update) elsif !block @backing_record.reactive_get!([[name]+args], force_update) else super end end
method_missing_warning(name)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 84 def method_missing_warning(name) @backing_record.deprecation_warning("Server side method #{name} must be defined using the 'server_method' macro.") end
model_name()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 55 def model_name # in reality should return ActiveModel::Name object, blah blah self.class.model_name end
new?()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 141 def new? @backing_record.new? end
primary_key()
click to toggle source
revert()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 60 def revert @backing_record.revert end
save(opts = {}, &block)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 125 def save(opts = {}, &block) @backing_record.save(opts.has_key?(:validate) ? opts[:validate] : true, opts[:force], &block) end
saving?()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 129 def saving? @backing_record.saving? end
type()
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 39 def type @backing_record.reactive_get!(:type, nil) end
type=(val)
click to toggle source
# File lib/reactive_record/active_record/instance_methods.rb, line 43 def type=(val) @backing_record.reactive_set!(:type, backing_record.convert(:type, val)) end