Class: ActiveSet::ActiveRecordSetInstruction
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ActiveSet::ActiveRecordSetInstruction
- Defined in:
- lib/active_set/active_record_set_instruction.rb
Instance Method Summary collapse
-
#arel_column ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName.
-
#arel_operator ⇒ Object
rubocop:enable Lint/UnderscorePrefixedVariableName.
- #arel_table ⇒ Object
- #arel_type ⇒ Object
-
#arel_value ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName.
- #attribute_model ⇒ Object
-
#case_insensitive_operation? ⇒ Boolean
rubocop:enable Lint/UnderscorePrefixedVariableName.
- #initial_relation ⇒ Object
-
#initialize(attribute_instruction, set) ⇒ ActiveRecordSetInstruction
constructor
A new instance of ActiveRecordSetInstruction.
Constructor Details
#initialize(attribute_instruction, set) ⇒ ActiveRecordSetInstruction
Returns a new instance of ActiveRecordSetInstruction.
5 6 7 8 9 |
# File 'lib/active_set/active_record_set_instruction.rb', line 5 def initialize(attribute_instruction, set) @attribute_instruction = attribute_instruction @set = set super(@attribute_instruction) end |
Instance Method Details
#arel_column ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName
35 36 37 38 39 40 |
# File 'lib/active_set/active_record_set_instruction.rb', line 35 def arel_column _arel_column = arel_table[@attribute_instruction.attribute] return _arel_column.lower if case_insensitive_operation? _arel_column end |
#arel_operator ⇒ Object
rubocop:enable Lint/UnderscorePrefixedVariableName
43 44 45 |
# File 'lib/active_set/active_record_set_instruction.rb', line 43 def arel_operator @attribute_instruction.operator(default: :eq) end |
#arel_table ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_set/active_record_set_instruction.rb', line 23 def arel_table # This is to work around an bug in ActiveRecord, # where BINARY fields aren't found properly when using # the `arel_table` class method to build an ARel::Node if arel_type == :binary Arel::Table.new(attribute_model.table_name) else attribute_model.arel_table end end |
#arel_type ⇒ Object
17 18 19 20 21 |
# File 'lib/active_set/active_record_set_instruction.rb', line 17 def arel_type attribute_model .columns_hash[@attribute_instruction.attribute] .type end |
#arel_value ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName
48 49 50 51 52 53 |
# File 'lib/active_set/active_record_set_instruction.rb', line 48 def arel_value _arel_value = @attribute_instruction.value return _arel_value.downcase if case_insensitive_operation? _arel_value end |
#attribute_model ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_set/active_record_set_instruction.rb', line 60 def attribute_model return @set.klass if @attribute_instruction.associations_array.empty? return @attribute_model if defined? @attribute_model @attribute_model = @attribute_instruction .associations_array .reduce(@set) do |obj, assoc| obj.reflections[assoc.to_s]&.klass end end |
#case_insensitive_operation? ⇒ Boolean
rubocop:enable Lint/UnderscorePrefixedVariableName
56 57 58 |
# File 'lib/active_set/active_record_set_instruction.rb', line 56 def case_insensitive_operation? @attribute_instruction.case_insensitive? && arel_type.presence_in(%i[string text]) end |
#initial_relation ⇒ Object
11 12 13 14 15 |
# File 'lib/active_set/active_record_set_instruction.rb', line 11 def initial_relation return @set if @attribute_instruction.associations_array.empty? @set.eager_load(@attribute_instruction.associations_hash) end |