Class: ConditionalCounterCache::Reflection::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/conditional_counter_cache/reflection.rb

Overview

Utility wrapper of ‘option[:condition]`.

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Condition

Returns a new instance of Condition.

Parameters:

  • (Proc, String, Symbol, nil)


17
18
19
# File 'lib/conditional_counter_cache/reflection.rb', line 17

def initialize(value)
  @value = value
end

Instance Method Details

#call(record) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/conditional_counter_cache/reflection.rb', line 21

def call(record)
  case @value
  when Proc
    record.instance_exec(&@value)
  when nil
    true
  else
    record.send(@value)
  end
end