Class: Activecube::Query::Selector

Inherits:
Item
  • Object
show all
Defined in:
lib/activecube/query/selector.rb

Direct Known Subclasses

CombineSelector

Defined Under Namespace

Classes: CombineSelector, Operator

Constant Summary collapse

OPERATORS =
['eq','not_eq','gt','lt','gteq','lteq','in','not_in','between']
ARRAY_OPERATORS =
['in','not_in']
ARRAY_OPERATOR_MAP =
{
    'eq' => 'in',
    'not_eq' => 'not_in'
}

Instance Attribute Summary collapse

Attributes inherited from Item

#cube, #definition, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Item

#append_with!, #required_column_names

Constructor Details

#initialize(cube, key, definition, operator = nil) ⇒ Selector

Returns a new instance of Selector.



80
81
82
83
# File 'lib/activecube/query/selector.rb', line 80

def initialize cube, key, definition, operator = nil
  super cube, key, definition
  @operator = operator
end

Instance Attribute Details

#operatorObject (readonly)

Returns the value of attribute operator.



79
80
81
# File 'lib/activecube/query/selector.rb', line 79

def operator
  @operator
end

Class Method Details

.and(selectors) ⇒ Object



149
150
151
# File 'lib/activecube/query/selector.rb', line 149

def self.and(selectors)
  CombineSelector.new(selectors, Operator.new(:and, nil))
end

.or(selectors) ⇒ Object



145
146
147
# File 'lib/activecube/query/selector.rb', line 145

def self.or(selectors)
  CombineSelector.new(selectors, Operator.new(:or, nil) )
end

Instance Method Details

#==(other) ⇒ Object



133
134
135
# File 'lib/activecube/query/selector.rb', line 133

def == other
  eql? other
end

#alias!(new_key) ⇒ Object



113
114
115
# File 'lib/activecube/query/selector.rb', line 113

def alias! new_key
  self.class.new cube, new_key, definition, operator
end

#append_query(model, cube_query, table, query) ⇒ Object



117
118
119
120
# File 'lib/activecube/query/selector.rb', line 117

def append_query model, cube_query, table, query
  query = append_with!(model, cube_query, table, query)
  query.where(expression model, table, cube_query)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
# File 'lib/activecube/query/selector.rb', line 126

def eql?(other)
  return other.kind_of?(Selector) &&
      self.cube==other.cube &&
      self.operator == other.operator &&
      self.definition.class == other.definition.class
end

#expression(model, arel_table, cube_query) ⇒ Object



122
123
124
# File 'lib/activecube/query/selector.rb', line 122

def expression model, arel_table, cube_query
  definition.expression model, arel_table, self, cube_query
end

#hashObject



137
138
139
# File 'lib/activecube/query/selector.rb', line 137

def hash
  self.definition.class.hash + self.operator.hash
end

#to_sObject



141
142
143
# File 'lib/activecube/query/selector.rb', line 141

def to_s
  "Selector #{super}"
end