Class: CustomSort::Magic::Relation

Inherits:
CustomSort::Magic show all
Defined in:
lib/custom_sort/magic.rb

Instance Attribute Summary

Attributes inherited from CustomSort::Magic

#options, #query_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CustomSort::Magic

validate_period

Constructor Details

#initialize(**options) ⇒ Relation

Returns a new instance of Relation.



33
34
35
36
# File 'lib/custom_sort/magic.rb', line 33

def initialize(**options)
  super(**options.reject { |k, _| [:default_value, :carry_forward, :last, :current].include?(k) })
  @options = options
end

Class Method Details

.generate_relation(relation, field:, **options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/custom_sort/magic.rb', line 38

def self.generate_relation(relation, field:, **options)
  magic = CustomSort::Magic::Relation.new(**options)

  # generate ActiveRecord relation
  relation =
  RelationBuilder.new(
      relation,
      column: field,
      query_name: magic.query_name
    ).generate

  # add Groupdate info
  #magic.group_index = relation.group_values.size - 1
  #(relation.groupdate_values ||= []) << magic

  relation
end

.process_result(relation, result, **options) ⇒ Object

allow any options to keep flexible for future



57
58
59
60
61
62
# File 'lib/custom_sort/magic.rb', line 57

def self.process_result(relation, result, **options)
  relation.customsort_values.reverse.each do |gv|
    result = gv.perform(relation, result, default_value: options[:default_value])
  end
  result
end