Class: Exo::ScopeWraper
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- app/presenters/exo/scope_wraper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(scope, delegate = nil) ⇒ ScopeWraper
Returns a new instance of ScopeWraper.
7
8
9
10
|
# File 'app/presenters/exo/scope_wraper.rb', line 7
def initialize scope, delegate=nil
self.delegate = delegate
self._scope = scope.kind_of?(Exo::ScopeWraper) ? scope._scope : scope
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'app/presenters/exo/scope_wraper.rb', line 42
def method_missing meth, *args, &block
_rez = _scope.send meth, *args, &block
if keep? _rez
self._scope = _rez
self
else
_rez
end
end
|
Instance Attribute Details
#_scope ⇒ Object
Returns the value of attribute _scope.
3
4
5
|
# File 'app/presenters/exo/scope_wraper.rb', line 3
def _scope
@_scope
end
|
#delegate ⇒ Object
Returns the value of attribute delegate.
3
4
5
|
# File 'app/presenters/exo/scope_wraper.rb', line 3
def delegate
@delegate
end
|
Instance Method Details
#each(&block) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'app/presenters/exo/scope_wraper.rb', line 12
def each &block
if delegate
_scope.each do |item|
block.call delegate.wrap_item(item)
end
else
_scope.each &block
end
end
|
#find(*params) ⇒ Object
34
35
36
|
# File 'app/presenters/exo/scope_wraper.rb', line 34
def find *params
wrap _scope.find *params
end
|
#find_by(*params) ⇒ Object
38
39
40
|
# File 'app/presenters/exo/scope_wraper.rb', line 38
def find_by *params
wrap _scope.find_by *params
end
|
#first ⇒ Object
26
27
28
|
# File 'app/presenters/exo/scope_wraper.rb', line 26
def first
wrap _scope.first
end
|
#keep?(obj) ⇒ Boolean
22
23
24
|
# File 'app/presenters/exo/scope_wraper.rb', line 22
def keep? obj
obj.kind_of? ::Mongoid::Criteria
end
|
#last ⇒ Object
30
31
32
|
# File 'app/presenters/exo/scope_wraper.rb', line 30
def last
wrap _scope.last
end
|