Class: Babik::QuerySet::SetOperation

Inherits:
AbstractBase show all
Defined in:
lib/babik/queryset.rb

Overview

Each one of the set operations that can be executed in SQL

Direct Known Subclasses

Except, Intersect, Union

Instance Attribute Summary collapse

Attributes inherited from AbstractBase

#_aggregation, #_count, #_distinct, #_limit, #_lock_type, #_order, #_projection, #_select_related, #_where, #model

Instance Method Summary collapse

Methods inherited from AbstractBase

_execute_sql, #all, #each, #left_joins_by_alias

Methods included from Updatable

#update

Methods included from Sortable

#disorder!, #invert_order!, #order!, #order_by!, #ordered?

Methods included from SetOperations

#difference, #intersection, #union

Methods included from RelatedSelector

#select_related!

Methods included from SQLRenderizable

#sql

Methods included from Projectable

#project!, #projection?, #unproject!

Methods included from Lockable

#for_update!, #lock!, #lock?

Methods included from Limitable

#[], #exists?, #fetch, #limit!, #limit?, #unlimit!

Methods included from Filterable

#exclude!, #filter!, #get

Methods included from Distinguishable

#distinct!, #undistinct!

Methods included from NoneQuerySet

#none

Methods included from Deletable

#delete

Methods included from Countable

#count, #empty?, #exists?, #length, #size

Methods included from Clonable

#clone, #method_missing, #mutate_clone, #respond_to_missing?

Methods included from Bounded

#earliest, #first, #last, #latest

Methods included from Aggregatable

#aggregate

Constructor Details

#initialize(model, left_operand, right_operand) ⇒ SetOperation

Returns a new instance of SetOperation.



130
131
132
133
134
# File 'lib/babik/queryset.rb', line 130

def initialize(model, left_operand, right_operand)
  @left_operand = left_operand
  @right_operand = right_operand
  super(model)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Babik::QuerySet::Clonable

Instance Attribute Details

#left_operandObject (readonly)

Returns the value of attribute left_operand.



128
129
130
# File 'lib/babik/queryset.rb', line 128

def left_operand
  @left_operand
end

#right_operandObject (readonly)

Returns the value of attribute right_operand.



128
129
130
# File 'lib/babik/queryset.rb', line 128

def right_operand
  @right_operand
end

Instance Method Details

#operationObject



136
137
138
139
140
141
142
143
# File 'lib/babik/queryset.rb', line 136

def operation
  db_adapter = Babik::Database.config[:adapter]
  operation_name = self.class.to_s.split('::').last.upcase
  if %w[postgresql sqlite3].include?(db_adapter) || (%w[mysql2].include?(db_adapter) && operation_name == 'UNION')
    return operation_name
  end
  raise "#{db_adapter} does not support operation #{operation_name}"
end