Module: ActiveData::Model::Scopes::ScopeProxy
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_data/model/scopes.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/active_data/model/scopes.rb', line 40
def method_missing(method, *args, &block)
with_scope do
model = self.class._scope_model
if model.respond_to?(method)
self.class._scope_model.public_send(method, *args, &block)
else
super
end
end
end
|
Class Method Details
.for(model) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/active_data/model/scopes.rb', line 14
def self.for(model)
klass = Class.new(model._scope_base) do
include ActiveData::Model::Scopes::ScopeProxy
end
klass.define_singleton_method(:_scope_model) { model }
model.const_set('ScopeProxy', klass)
end
|
Instance Method Details
#respond_to_missing?(method, _) ⇒ Boolean
36
37
38
|
# File 'lib/active_data/model/scopes.rb', line 36
def respond_to_missing?(method, _)
super || self.class._scope_model.respond_to?(method)
end
|
#with_scope ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/active_data/model/scopes.rb', line 51
def with_scope
previous_scope = self.class._scope_model.current_scope
self.class._scope_model.current_scope = self
result = yield
self.class._scope_model.current_scope = previous_scope
result
end
|