Class: CacheCrispies::Optional
- Inherits:
-
Object
- Object
- CacheCrispies::Optional
- Defined in:
- lib/cache_crispies/optional.rb
Overview
Represents an optional condition
Instance Method Summary collapse
-
#initialize(key) ⇒ Optional
constructor
Returns a new instance of Optional.
-
#true_for?(serializer) ⇒ Boolean
Test the truthiness of the optional condition against a model and options.
-
#uid ⇒ Object
A system-wide unique ID used for memoizaiton.
Constructor Details
#initialize(key) ⇒ Optional
Returns a new instance of Optional
9 10 11 |
# File 'lib/cache_crispies/optional.rb', line 9 def initialize(key) @key = key end |
Instance Method Details
#true_for?(serializer) ⇒ Boolean
Test the truthiness of the optional condition against a model and options
26 27 28 29 30 |
# File 'lib/cache_crispies/optional.rb', line 26 def true_for?(serializer) included = Array(serializer..fetch(:include, [])).map(&:to_sym) included.include?(key) || included.include?(:*) end |
#uid ⇒ Object
A system-wide unique ID used for memoizaiton
16 17 18 19 |
# File 'lib/cache_crispies/optional.rb', line 16 def uid # Just reusing the key seems to make sense key end |