class CacheCrispies::Optional
Represents an optional condition
Attributes
key[R]
Public Class Methods
new(key)
click to toggle source
Returns a new instance of Optional
@param block [Proc] the key of the attribute to include
# File lib/cache_crispies/optional.rb, line 9 def initialize(key) @key = key end
Public Instance Methods
true_for?(serializer)
click to toggle source
Test the truthiness of the optional condition against a model and options
@param model [Object] typically ActiveRecord::Base, but could be anything @param options [Hash] any optional values from the serializer instance @return [Boolean] the condition's truthiness
# File lib/cache_crispies/optional.rb, line 26 def true_for?(serializer) included = Array(serializer.options.fetch(:include, [])).map(&:to_sym) included.include?(key) || included.include?(:*) end
uid()
click to toggle source
A system-wide unique ID used for memoizaiton
@eturn [Integer] the unique ID for this condition
# File lib/cache_crispies/optional.rb, line 16 def uid # Just reusing the key seems to make sense key end