Class: Wallaby::ActiveRecord::ModelServiceProvider::Querier::Transformer

Inherits:
Parslet::Transform
  • Object
show all
Defined in:
lib/adapters/wallaby/active_record/model_service_provider/querier/transformer.rb

Overview

Build up query using the results

Constant Summary collapse

SIMPLE_OPERATORS =

:nodoc:

{ # :nodoc:
  ':' => :eq,
  ':=' => :eq,
  ':!' => :not_eq,
  ':!=' => :not_eq,
  ':<>' => :not_eq,
  ':~' => :matches,
  ':^' => :matches,
  ':$' => :matches,
  ':!~' => :does_not_match,
  ':!^' => :does_not_match,
  ':!$' => :does_not_match,
  ':>' => :gt,
  ':>=' => :gteq,
  ':<' => :lt,
  ':<=' => :lteq
}.freeze
SEQUENCE_OPERATORS =

:nodoc:

{ # :nodoc:
  ':' => :in,
  ':=' => :in,
  ':!' => :not_in,
  ':!=' => :not_in,
  ':<>' => :not_in,
  ':()' => :between,
  ':!()' => :not_between
}.freeze
SEQUENCE_JOIN_OPERATORS =

:nodoc:

{ # :nodoc:
  ':' => :or,
  ':=' => :or,
  ':!' => :and,
  ':!=' => :and,
  ':<>' => :and
}.freeze
BETWEEN_OPERATORS =

:nodoc:

{ # :nodoc:
  ':()' => true,
  ':!()' => true
}.freeze

Class Method Summary collapse

Class Method Details

.execute(query_string) ⇒ Array

Parameters:

  • query_string (String)

Returns:

  • (Array)


106
107
108
109
# File 'lib/adapters/wallaby/active_record/model_service_provider/querier/transformer.rb', line 106

def execute(query_string)
  result = new.apply Parser.new.parse(query_string || EMPTY_STRING)
  result.is_a?(Array) ? result : [result]
end

.to_origin(exp) ⇒ String

Returns origin expression.

Parameters:

  • exp (Hash, nil)

    transformed expression

Returns:

  • (String)

    origin expression



120
121
122
# File 'lib/adapters/wallaby/active_record/model_service_provider/querier/transformer.rb', line 120

def to_origin(exp)
  "'#{exp['left']}#{exp['op']}#{exp['right']}'"
end

.warn(message, exp = nil) ⇒ nil

Parameters:

  • message (String)
  • exp (Hash, nil) (defaults to: nil)

    transformed expression

Returns:

  • (nil)


114
115
116
# File 'lib/adapters/wallaby/active_record/model_service_provider/querier/transformer.rb', line 114

def warn(message, exp = nil)
  Logger.warn message, exp: to_origin(exp), sourcing: 2
end