Module: ActiveRecord::InstanceMethods
- Included in:
- Base
- Defined in:
- lib/reactive_record/active_record/instance_methods.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 48
def method_missing(name, *args, &block)
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, args[0])
elsif args.count == 0 && !block
@backing_record.reactive_get!(name)
else
super
end
end
|
Instance Method Details
#==(ar_instance) ⇒ Object
44
45
46
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 44
def ==(ar_instance)
@backing_record == ar_instance.instance_eval { @backing_record }
end
|
#attributes ⇒ Object
5
6
7
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 5
def attributes
@backing_record.attributes
end
|
#changed? ⇒ Boolean
40
41
42
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 40
def changed?
@backing_record.changed?
end
|
#destroy(&block) ⇒ Object
69
70
71
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 69
def destroy(&block)
@backing_record.destroy &block
end
|
#id ⇒ Object
23
24
25
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 23
def id
@backing_record.reactive_get!(primary_key)
end
|
#id=(value) ⇒ Object
27
28
29
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 27
def id=(value)
@backing_record.id = value
end
|
#initialize(hash = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 9
def initialize(hash = {})
if hash.is_a? ReactiveRecord::Base
@backing_record = hash
else
hash[primary_key] = nil
@backing_record = ReactiveRecord::Base.new(self.class, hash, self)
end
end
|
#model_name ⇒ Object
31
32
33
34
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 31
def model_name
self.class.model_name
end
|
#primary_key ⇒ Object
19
20
21
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 19
def primary_key
self.class.primary_key
end
|
#revert ⇒ Object
36
37
38
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 36
def revert
@backing_record.revert
end
|
#save(&block) ⇒ Object
61
62
63
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 61
def save(&block)
@backing_record.save &block
end
|
#saving? ⇒ Boolean
65
66
67
|
# File 'lib/reactive_record/active_record/instance_methods.rb', line 65
def saving?
@backing_record.saving?
end
|