Class: Alchemy::CacheControlType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
app/types/alchemy/cache_control_type.rb

Overview

Casts a page layout cache / element page_cache config value into an CacheControl and validates the hash grammar at definition-load time (see #assert_valid_value, called eagerly on attribute assignment).

Constant Summary collapse

ALLOWED_KEYS =
[:visibility, :max_age, :no_cache, :no_store].freeze

Instance Method Summary collapse

Instance Method Details

#assert_valid_value(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/types/alchemy/cache_control_type.rb', line 14

def assert_valid_value(value)
  case value
  when nil, true, false, Alchemy::CacheControl
    nil
  when Integer
    assert_valid_max_age!(value)
  when Hash
    assert_valid_hash!(value)
  else
    raise ArgumentError,
      "#{value.inspect} is not a valid cache setting. " \
      "Must be true, false, an Integer, or a Hash."
  end
end

#cast(value) ⇒ Object



10
11
12
# File 'app/types/alchemy/cache_control_type.rb', line 10

def cast(value)
  Alchemy::CacheControl.parse(value)
end