Class: ActiveResource::Scope
- Inherits:
-
Object
- Object
- ActiveResource::Scope
show all
- Includes:
- Enumerable
- Defined in:
- lib/active_resource/scopes.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource_class) ⇒ Scope
Returns a new instance of Scope.
26
27
28
|
# File 'lib/active_resource/scopes.rb', line 26
def initialize(resource_class)
@resource_class = resource_class
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/active_resource/scopes.rb', line 46
def method_missing(name, *args)
return super unless scopes.key? name
scope = scopes[name]
scope = scope.call(*args) if scope.is_a? Proc
where scope.params
end
|
Instance Attribute Details
#resource_class ⇒ Object
Returns the value of attribute resource_class.
24
25
26
|
# File 'lib/active_resource/scopes.rb', line 24
def resource_class
@resource_class
end
|
Instance Method Details
#params ⇒ Object
30
31
32
|
# File 'lib/active_resource/scopes.rb', line 30
def params
@params ||= {}
end
|
#to_a ⇒ Object
34
35
36
|
# File 'lib/active_resource/scopes.rb', line 34
def to_a
resource_class.find :all, :params => params
end
|
#where(params = {}) ⇒ Object
40
41
42
|
# File 'lib/active_resource/scopes.rb', line 40
def where(params = {})
dup.tap { |scope| scope.params.update params }
end
|