Class: Lotus::Config::Cookies Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/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 < Lotus::Application
    configure do
      # ...
      cookies true
    end
  end
end

Enable cookies with options

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

Parameters:

  • options (Hash, TrueClass, FalseClass) (defaults to: {})

    optional cookies options

  • configuration (Lotus::Configuration)

    the application configuration

See Also:

Since:

  • 0.3.0



51
52
53
54
55
# File 'lib/lotus/config/cookies.rb', line 51

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

Returns:

  • (Hash)

    options for cookies

Since:

  • 0.3.0



15
16
17
# File 'lib/lotus/config/cookies.rb', line 15

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

Returns:

  • (TrueClass, FalseClass)

    enabled cookies

Since:

  • 0.3.0



63
64
65
# File 'lib/lotus/config/cookies.rb', line 63

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