Class: Rql::Scope::RqlScope

Inherits:
Object show all
Defined in:
lib/rql/scope/rql_scope.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ RqlScope

Returns a new instance of RqlScope.



4
5
6
7
8
# File 'lib/rql/scope/rql_scope.rb', line 4

def initialize(scope)
  @block_methods = BlockMethods.new(scope)
  @param_methods = ParamMethods.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



14
15
16
17
18
19
20
21
22
# File 'lib/rql/scope/rql_scope.rb', line 14

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

#merge(other) ⇒ Object



31
32
33
34
# File 'lib/rql/scope/rql_scope.rb', line 31

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

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/rql/scope/rql_scope.rb', line 24

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

#scopeObject



10
11
12
# File 'lib/rql/scope/rql_scope.rb', line 10

def scope
  @scope
end

#to_aObject



36
37
38
# File 'lib/rql/scope/rql_scope.rb', line 36

def to_a
  scope.to_a
end