Class: InPlaceRelation::Wrapper
- Inherits:
-
Object
- Object
- InPlaceRelation::Wrapper
show all
- Defined in:
- lib/in_place_relation.rb
Constant Summary
collapse
- METHODS_TO_WRAP =
ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS + ActiveRecord::Relation::SINGLE_VALUE_METHODS + [:merge]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(relation) ⇒ Wrapper
35
36
37
|
# File 'lib/in_place_relation.rb', line 35
def initialize( relation )
@relation = relation
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/in_place_relation.rb', line 43
def method_missing( meth, *args, &block )
result = @relation.send( meth, *args, &block )
if result.is_a?( ActiveRecord::Relation )
singleton_class.class_eval do
define_method( meth ) do |*args, &block|
@relation = @relation.send( meth, *args )
return self
end
end
@relation = result
return self
else
return result
end
end
|
Instance Attribute Details
#relation ⇒ Object
Wrapped ActiveRecord::Relation object
24
25
26
|
# File 'lib/in_place_relation.rb', line 24
def relation
@relation
end
|
Instance Method Details
#in_place ⇒ Object
61
62
63
|
# File 'lib/in_place_relation.rb', line 61
def in_place
return self
end
|
#inspect ⇒ Object
39
40
41
|
# File 'lib/in_place_relation.rb', line 39
def inspect
return "#{self.class}:#{object_id}"
end
|