Class: Rql::Scope::RqlScope
- Includes:
- BlockMethods, ParamMethods
- Defined in:
- lib/rql/scope/rql_scope.rb
Instance Method Summary collapse
-
#arel ⇒ Arel::SelectManager
Gets the underlying arel object for the scope.
-
#initialize(scope) ⇒ RqlScope
constructor
A new instance of RqlScope.
-
#merge(other) ⇒ Rql::Scope::RqlScope
Creates a new scope merging the current scope with the other scope.
- #method_missing(method_name, *params, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#scope ⇒ ActiveRecord::Relation
Gets the underlying ActiveRecord Relation object for the scope.
-
#to_a ⇒ Array
Executes the scope against the database returning the results as an array.
Methods included from BlockMethods
#includes, #joins, #order, #select, #where
Methods included from ParamMethods
#includes, #joins, #order, #select, #where
Constructor Details
#initialize(scope) ⇒ RqlScope
Returns a new instance of RqlScope.
8 9 10 11 12 |
# File 'lib/rql/scope/rql_scope.rb', line 8 def initialize(scope) @block_methods = BlockMethodGroup.new(scope) @param_methods = ParamMethodGroup.new(scope) @scope = scope end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *params, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/rql/scope/rql_scope.rb', line 21 def method_missing(method_name, *params, &block) if block && @block_methods.respond_to?(method_name) RqlScope.new(@block_methods.send(method_name, &block)) elsif @param_methods.respond_to?(method_name) RqlScope.new(@param_methods.send(method_name, *params)) else scope.send(method_name, *params) end end |
Instance Method Details
#arel ⇒ Arel::SelectManager
Gets the underlying arel object for the scope
50 51 52 |
# File 'lib/rql/scope/rql_scope.rb', line 50 def arel scope.arel end |
#merge(other) ⇒ Rql::Scope::RqlScope
Creates a new scope merging the current scope with the other scope
42 43 44 45 |
# File 'lib/rql/scope/rql_scope.rb', line 42 def merge(other) other = other.scope if other.is_a?(RqlScope) RqlScope.new(scope.merge(other)) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/rql/scope/rql_scope.rb', line 31 def respond_to_missing?(method_name, include_private = false) @block_methods.respond_to?(method_name, include_private) || @param_methods.respond_to?(method_name, include_private) || super.respond_to?(method_name, include_private) || super end |
#scope ⇒ ActiveRecord::Relation
Gets the underlying ActiveRecord Relation object for the scope
17 18 19 |
# File 'lib/rql/scope/rql_scope.rb', line 17 def scope @scope end |
#to_a ⇒ Array
Executes the scope against the database returning the results as an array
57 58 59 |
# File 'lib/rql/scope/rql_scope.rb', line 57 def to_a scope.to_a end |