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
38
39
40
|
# File 'lib/active_data/model/scopes.rb', line 38
def method_missing method, *args, &block
with_scope { self.class._scope_model.public_send(method, *args, &block) }
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
34
35
36
|
# File 'lib/active_data/model/scopes.rb', line 34
def respond_to_missing? method, _
super || self.class._scope_model.respond_to?(method)
end
|
#with_scope ⇒ Object
42
43
44
45
46
47
|
# File 'lib/active_data/model/scopes.rb', line 42
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
|