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?(model, options = {}) ⇒ Boolean
Test the truthiness of the condition against a model and options.
-
#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?(model, options = {}) ⇒ Boolean
Test the truthiness of the condition against a model and options
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cache_crispies/condition.rb', line 27 def true_for?(model, = {}) !!case block.arity when 0 block.call when 1 block.call(model) else block.call(model, ) end 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 |