Class: Rql::Dsl::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logic

#&, #|

Methods included from Orders

#asc, #desc

Methods included from Maths

#*, #+, #-, #/

Methods included from Comparisons

#<, #<=, #==, #===, #>, #>=, #end_with?, #in?, #include?, #start_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.



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

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 Attribute Details

#arelObject

Returns the value of attribute arel.



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

def arel
  @arel
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#as(name) ⇒ Object



28
29
30
# File 'lib/rql/dsl/context.rb', line 28

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

#build_context(name) ⇒ Object



23
24
25
26
# File 'lib/rql/dsl/context.rb', line 23

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

#context_nameObject



19
20
21
# File 'lib/rql/dsl/context.rb', line 19

def context_name
  @name
end

#rqlObject



32
33
34
# File 'lib/rql/dsl/context.rb', line 32

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

#where(*attributes, &block) ⇒ Object



36
37
38
39
40
# File 'lib/rql/dsl/context.rb', line 36

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