Class: Rql::Dsl::Context

Inherits:
Base show all
Includes:
Aggregations, Comparisons, Logic, Maths, Orders
Defined in:
lib/rql/dsl/context.rb

Instance Method Summary collapse

Methods included from Logic

#&, #|

Methods included from Orders

#asc, #desc

Methods included from Maths

#*, #+, #-, #/

Methods included from Comparisons

#<, #<=, #==, #===, #>, #>=, #ends_with?, #in?, #include?, #starts_with?

Methods included from Aggregations

#average, #calculate, #count, #maximum, #minimum, #sum

Methods inherited from Base

#method_missing, #respond_to_missing?

Constructor Details

#initialize(scope, arel, name = nil) ⇒ Context

Returns a new instance of Context.



10
11
12
13
14
15
# File 'lib/rql/dsl/context.rb', line 10

def initialize(scope, arel, name = nil)
  @scope = scope
  @model = scope.unscoped
  @arel = arel
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rql::Dsl::Base

Instance Method Details

#arelObject



17
18
19
# File 'lib/rql/dsl/context.rb', line 17

def arel
  @arel
end

#as(name) ⇒ Object



26
27
28
# File 'lib/rql/dsl/context.rb', line 26

def as(name)
  Context.new(@model, arel.as(name.to_s))
end

#build_context(name) ⇒ Object



21
22
23
24
# File 'lib/rql/dsl/context.rb', line 21

def build_context(name)
  model = @name.to_s.classify.constantize
  Context.new(model, model.arel_table[name], name)
end

#rqlObject



30
31
32
# File 'lib/rql/dsl/context.rb', line 30

def rql
  Context.new(@scope.rql, @arel, @name)
end

#where(*attributes, &block) ⇒ Object



34
35
36
37
38
# File 'lib/rql/dsl/context.rb', line 34

def where(*attributes, &block)
  model = @name.to_s.classify.constantize
  model = model.rql if @scope.is_a?(Scope::RqlScope)
  Context.new(@scope.merge(model.where(*attributes, &block)), @arel, @name)
end