Class: Hanami::Config::Cookies Private

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

Overview

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

Cookies configuration

Since:

  • 0.3.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, 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.

Cookies configuration

httponly option enabled by default. Prevent attackers to steal cookies via JavaScript, Eg. alert(document.cookie) will fail

Examples:

Enable cookies with boolean

module Web
  class Application < Hanami::Application
    configure do
      # ...
      cookies true
    end
  end
end

Enable cookies with options

module Web
  class Application < Hanami::Application
    configure do
      # ...
      cookies max_age: 300
    end
  end
end

See Also:

Since:

  • 0.3.0


52
53
54
55
56
# File 'lib/hanami/config/cookies.rb', line 52

def initialize(configuration, options = {})
  @options         = options
  @default_options = { httponly: true, secure: configuration.ssl? }
  @default_options.merge!(options) if options.is_a?(::Hash)
end

Instance Attribute Details

#default_optionsHash (readonly)

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.

Return the routes for this application

Since:

  • 0.3.0


16
17
18
# File 'lib/hanami/config/cookies.rb', line 16

def default_options
  @default_options
end

Instance Method Details

#enabled?TrueClass, FalseClass

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.

Return if cookies are enabled

Since:

  • 0.3.0


64
65
66
# File 'lib/hanami/config/cookies.rb', line 64

def enabled?
  @options.respond_to?(:empty?) ? !@options.empty? : !!@options
end