Class: ActiveRecordExtended::QueryMethods::FosterSelect::SelectHelper

Inherits:
Object
  • Object
show all
Includes:
Utilities::OrderBy, Utilities::Support
Defined in:
lib/active_record_extended/query_methods/foster_select.rb

Constant Summary collapse

AGGREGATE_ONE_LINERS =
/^(exists|sum|max|min|avg|count|jsonb?_agg|(bit|bool)_(and|or)|xmlagg|array_agg)$/.freeze

Constants included from Utilities::Support

Utilities::Support::A_TO_Z_KEYS

Instance Method Summary collapse

Methods included from Utilities::OrderBy

#inline_order_by, #order_by_expression, #process_ordering_arguments!, #scope_preprocess_order_args, #to_ordered_table_path

Methods included from Utilities::Support

#double_quote, #flatten_safely, #flatten_to_sql, #from_clause_constructor, #generate_grouping, #generate_named_function, #group_when_needed, #key_generator, #literal_key, #needs_to_be_grouped?, #nested_alias_escape, #pipe_cte_with!, #to_arel_sql, #wrap_with_agg_array, #wrap_with_array

Constructor Details

#initialize(scope) ⇒ SelectHelper

Returns a new instance of SelectHelper.



12
13
14
# File 'lib/active_record_extended/query_methods/foster_select.rb', line 12

def initialize(scope)
  @scope = scope
end

Instance Method Details

#build_foster_select(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_record_extended/query_methods/foster_select.rb', line 16

def build_foster_select(*args)
  flatten_safely(args).each do |select_arg|
    case select_arg
    when String, Symbol
      select!(select_arg)
    when Hash
      select_arg.each_pair do |alias_name, options_or_column|
        case options_or_column
        when Array
          process_array!(options_or_column, alias_name)
        when Hash
          process_hash!(options_or_column, alias_name)
        else
          select!(options_or_column, alias_name)
        end
      end
    end
  end
end