Class: CacheCrispies::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_crispies/condition.rb

Overview

Represents an instance of a conditional built by a Base.show_if call

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Condition

Returns a new instance of Condition

Parameters:

  • block (Proc)

    a block containing the logic for the condition



10
11
12
# File 'lib/cache_crispies/condition.rb', line 10

def initialize(block)
  @block = block
end

Instance Method Details

#true_for?(serializer) ⇒ Boolean

Test the truthiness of the condition against the serializer instance

Parameters:

  • serializer (Object)

    CacheCrispies::Base serializer instance

Returns:

  • (Boolean)

    the condition’s truthiness



26
27
28
29
30
# File 'lib/cache_crispies/condition.rb', line 26

def true_for?(serializer)
  return !!serializer.public_send(block) if block.is_a?(Symbol)

  !!execute_block(serializer.model, serializer.options)
end

#uidObject

A system-wide unique ID used for memoizaiton



17
18
19
20
# File 'lib/cache_crispies/condition.rb', line 17

def uid
  # Just reusing the block's object_id seems to make sense
  block.object_id
end