Class: CacheCrispies::Condition
- Inherits:
-
Object
- Object
- CacheCrispies::Condition
- 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
-
#initialize(block) ⇒ Condition
constructor
Returns a new instance of Condition.
-
#true_for?(serializer) ⇒ Boolean
Test the truthiness of the condition against the serializer instance.
-
#uid ⇒ Object
A system-wide unique ID used for memoizaiton.
Constructor Details
#initialize(block) ⇒ Condition
Returns a new instance of 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
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.) end |
#uid ⇒ Object
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 |