Class: Hanami::Config::Actions::Cookies

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/config/actions/cookies.rb

Overview

Wrapper for app-level config of HTTP cookies for Hanami actions.

This decorates the hash of cookie options that is otherwise directly configurable on actions, and adds the ‘enabled?` method to allow app base action to determine whether to include the `Action::Cookies` module.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cookies

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new ‘Cookies`.

You should not need to initialize this class directly. Instead use Hanami::Config::Actions#cookies.

Since:

  • 2.0.0



30
31
32
# File 'lib/hanami/config/actions/cookies.rb', line 30

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsHash (readonly)

Returns the cookie options.

Returns:

  • (Hash)

Since:

  • 2.0.0



21
22
23
# File 'lib/hanami/config/actions/cookies.rb', line 21

def options
  @options
end

Instance Method Details

#enabled?Boolean

Returns true if any cookie options have been provided.

Returns:

  • (Boolean)

Since:

  • 2.0.0



40
41
42
# File 'lib/hanami/config/actions/cookies.rb', line 40

def enabled?
  !options.nil?
end

#to_hHash

Returns the cookie options.

If no options have been provided, returns an empty hash.

Returns:

  • (Hash)

Since:

  • 2.0.0



51
52
53
# File 'lib/hanami/config/actions/cookies.rb', line 51

def to_h
  options.to_h
end