Class: Rql::Dsl::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functions

#downcase

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.



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

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.



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

def arel
  @arel
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#as(name) ⇒ Object



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

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

#build_context(name) ⇒ Object



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

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

#context_nameObject



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

def context_name
  @name
end

#rqlObject



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

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

#where(*attributes, &block) ⇒ Object



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

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