Module: PassiveRecord::InstanceMethods
- Defined in:
- lib/passive_record/instance_methods.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/passive_record/instance_methods.rb', line 32
def method_missing(meth, *args, &blk)
if (matching_relation = find_relation_by_target_name_symbol(meth))
send_relation(matching_relation, meth, *args)
else
super(meth,*args,&blk)
end
end
|
Instance Method Details
#attribute_names ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/passive_record/instance_methods.rb', line 41
def attribute_names
attr_names = instance_variables
attr_names += self.class.associations_id_syms
attr_names += members rescue []
attr_names.reject! { |name| name.to_s.start_with?("@_") }
attr_names - blacklisted_attribute_names
end
|
#blacklisted_attribute_names ⇒ Object
49
50
51
|
# File 'lib/passive_record/instance_methods.rb', line 49
def blacklisted_attribute_names
[]
end
|
#respond_to?(meth, *args, &blk) ⇒ Boolean
24
25
26
27
28
29
30
|
# File 'lib/passive_record/instance_methods.rb', line 24
def respond_to?(meth,*args,&blk)
if find_relation_by_target_name_symbol(meth)
true
else
super(meth,*args,&blk)
end
end
|
#to_h ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/passive_record/instance_methods.rb', line 14
def to_h
Hash[
attribute_names.
map do |name| [
name.to_s.gsub("@","").to_sym, (instance_variable_get(name) rescue send(name))] end
]
end
|
#update(attrs = {}) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/passive_record/instance_methods.rb', line 3
def update(attrs={})
attrs.each do |k,v|
send("#{k}=", v)
end
self.class.after_update_hooks.each do |hook|
hook.run(self)
end
end
|