Class: DumpCleaner::Conditions

Inherits:
Object
  • Object
show all
Defined in:
lib/dump_cleaner/conditions.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition_config) ⇒ Conditions

Returns a new instance of Conditions.



3
4
5
# File 'lib/dump_cleaner/conditions.rb', line 3

def initialize(condition_config)
  @conditions = condition_config
end

Class Method Details

.evaluate_to_true_in_step?(conditions:, step_context:) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/dump_cleaner/conditions.rb', line 17

def self.evaluate_to_true_in_step?(conditions:, step_context:)
  new(conditions).evaluate_to_true?(record: step_context.record, column_value: step_context.orig_value)
end

Instance Method Details

#evaluate_to_true?(record:, column_value: nil) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
# File 'lib/dump_cleaner/conditions.rb', line 7

def evaluate_to_true?(record:, column_value: nil)
  return false unless @conditions

  Array(@conditions).map do |condition_config|
    column = condition_config.column
    conversion, op, value = parse_condition(condition_config)
    (column ? record[column] : column_value).send(conversion || :itself).send(op, value)
  end.any?
end