Class: ActiveSet::Filtering::Enumerable::SetInstruction

Inherits:
EnumerableSetInstruction show all
Defined in:
lib/active_set/filtering/enumerable/set_instruction.rb

Instance Method Summary collapse

Methods inherited from EnumerableSetInstruction

#attribute_value_for, #case_insensitive_operation_for?, #initialize, #instruction_value

Constructor Details

This class inherits a constructor from ActiveSet::EnumerableSetInstruction

Instance Method Details

#attribute_classObject



36
37
38
# File 'lib/active_set/filtering/enumerable/set_instruction.rb', line 36

def attribute_class
  attribute_instance&.class
end

#attribute_instanceObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/active_set/filtering/enumerable/set_instruction.rb', line 25

def attribute_instance
  return set_item if @attribute_instruction.associations_array.empty?
  return @attribute_model if defined? @attribute_model

  @attribute_model = @attribute_instruction
                     .associations_array
                     .reduce(set_item) do |obj, assoc|
    obj.public_send(assoc)
  end
end

#item_matches_query?(item) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/active_set/filtering/enumerable/set_instruction.rb', line 11

def item_matches_query?(item)
  return query_result_for(item, query_attribute_for(instruction_value)) unless operator_hash.key?(:reducer)

  Array.wrap(instruction_value).public_send(operator_hash[:reducer]) do |value|
    query_result_for(item, query_attribute_for(value))
  end
end

#set_itemObject



19
20
21
22
23
# File 'lib/active_set/filtering/enumerable/set_instruction.rb', line 19

def set_item
  return @set_item if defined? @set_item

  @set_item = @set.find(&:present?)
end