Class: QueryDelegator
- Inherits:
-
Object
- Object
- QueryDelegator
- Defined in:
- lib/query_delegator.rb,
lib/query_delegator/be.rb,
lib/query_delegator/version.rb,
lib/query_delegator/memory_fetching.rb,
lib/query_delegator/respond_or_none.rb
Defined Under Namespace
Modules: Be, MemoryFetching, RespondOrNone
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.[](delegating) ⇒ Object
Returns a Proc which delegates an ActiveRecord model scope to query object instance method.
-
.to_proc ⇒ Object
Returns a Proc which wraps an ActiveRecord scope in a new query object instance.
Instance Method Summary collapse
-
#initialize(relation) ⇒ QueryDelegator
constructor
A new instance of QueryDelegator.
Constructor Details
#initialize(relation) ⇒ QueryDelegator
Returns a new instance of QueryDelegator.
10 11 12 |
# File 'lib/query_delegator.rb', line 10 def initialize(relation) @current_scope = relation.all end |
Class Method Details
.[](delegating) ⇒ Object
Returns a Proc which delegates an ActiveRecord model scope to query object instance method.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/query_delegator.rb', line 29 def [](delegating) delegator = self if public_instance_method(delegating).arity.zero? proc do delegator.new(self).public_send delegating end else proc do |*| delegator.new(self).public_send delegating, * end end end |
.to_proc ⇒ Object
Returns a Proc which wraps an ActiveRecord scope in a new query object instance.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/query_delegator.rb', line 16 def to_proc delegator = self proc do |*args| if equal? delegator new(*args) else delegator.(self, *args) end end end |