Skip to content

Commit

Permalink
Rename default_cookie_options into cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Mar 20, 2015
1 parent 53c321f commit 0f85168
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
12 changes: 6 additions & 6 deletions lib/lotus/action/cookie_jar.rb
Expand Up @@ -36,10 +36,10 @@ class CookieJar
# @return [CookieJar]
#
# @since 0.1.0
def initialize(env, headers, default_cookies_options)
@_headers = headers
@cookies = Utils::Hash.new(extract(env)).symbolize!
@default_cookies_options = default_cookies_options
def initialize(env, headers, default_options)
@_headers = headers
@cookies = Utils::Hash.new(extract(env)).symbolize!
@default_options = default_options
end

# Finalize itself, by setting the proper headers to add and remove
Expand Down Expand Up @@ -83,15 +83,15 @@ def []=(key, value)
#
# Cookies values provided by user are respected
#
# @since x.x.x
# @since 0.4.0
# @api private
def _merge_default_values(value)
cookies_options = if value.is_a? Hash
value
else
{ value: value }
end
@default_cookies_options.merge cookies_options
@default_options.merge cookies_options
end
# Extract the cookies from the raw Rack env.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/action/cookies.rb
Expand Up @@ -41,7 +41,7 @@ module Cookies
# end
# end
def cookies
@cookies ||= CookieJar.new(@_env.dup, headers, configuration.default_cookies_options)
@cookies ||= CookieJar.new(@_env.dup, headers, configuration.cookies)
end

private
Expand Down
8 changes: 4 additions & 4 deletions lib/lotus/action/flash.rb
Expand Up @@ -14,7 +14,7 @@ class Flash

# Session key where the last request_id is stored
#
# @since x.x.x
# @since 0.4.0
# @api private
LAST_REQUEST_KEY = :__last_request_id

Expand Down Expand Up @@ -149,7 +149,7 @@ def _values
#
# @return [TrueClass,FalseClass] the result of the check
#
# @since x.x.x
# @since 0.4.0
# @api private
#
# @see Lotus::Action::Flash#expire_stale!
Expand All @@ -161,7 +161,7 @@ def delete?(request_id)
#
# @return [Hash] the flash of last request
#
# @since x.x.x
# @since 0.4.0
# @api private
def last_request_flash
flash[@last_request_id] || {}
Expand All @@ -171,7 +171,7 @@ def last_request_flash
# is current flash is not empty.
#
# @return [void]
# @since x.x.x
# @since 0.4.0
# @api private
def set_last_request_id!
@session[LAST_REQUEST_KEY] = @request_id if !empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/action/head.rb
Expand Up @@ -21,7 +21,7 @@ module Head
# "The response MAY include new or updated metainformation in the form
# of entity-headers".
#
# @since x.x.x
# @since 0.4.0
# @api private
#
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5
Expand Down
4 changes: 2 additions & 2 deletions lib/lotus/action/params.rb
Expand Up @@ -28,7 +28,7 @@ class Params

# Separator for #get
#
# @since x.x.x
# @since 0.4.0
# @api private
#
# @see Lotus::Action::Params#get
Expand Down Expand Up @@ -152,7 +152,7 @@ def [](key)
#
# @return [Object,NilClass] return the associated value, if found
#
# @since x.x.x
# @since 0.4.0
#
# @example
# require 'lotus/controller'
Expand Down
6 changes: 3 additions & 3 deletions lib/lotus/action/rack/callable.rb
Expand Up @@ -9,7 +9,7 @@ module Callable
# @param env [Hash] the full Rack env or the params. This value may vary,
# see the examples below.
#
# @since x.x.x
# @since 0.4.0
#
# @see Lotus::Action::Rack::ClassMethods#rack_builder
# @see Lotus::Action::Rack::ClassMethods#use
Expand All @@ -21,7 +21,7 @@ module Callable
# def initialize(app)
# @app = app
# end
#
#
# def call(env)
# #...
# end
Expand All @@ -44,4 +44,4 @@ def call(env)
end
end
end
end
end
37 changes: 18 additions & 19 deletions lib/lotus/controller/configuration.rb
Expand Up @@ -473,7 +473,7 @@ def default_charset(charset = nil)
#
# By default this value is an empty hash.
#
# @since x.x.x
# @since 0.4.0
#
# @example Getting the value
# require 'lotus/controller'
Expand All @@ -498,36 +498,35 @@ def default_headers(headers = nil)
end
end


# Set default cookies options for all responses
#
# By default this value is an empty hash.
#
# @since x.x.x
# @since 0.4.0
#
# @example Getting the value
# require 'lotus/controller'
#
# Lotus::Controller.configuration.default_cookies_options # => {}
# Lotus::Controller.configuration.cookies # => {}
#
# @example Setting the value
# require 'lotus/controller'
#
# Lotus::Controller.configure do
# default_cookies_options({
# cookies({
# domain: 'lotusrb.org',
# path: '/controller',
# secure: true,
# httponly: true
# })
# end
def default_cookies_options(options = nil)
def cookies(options = nil)
if options
@default_cookies_options.merge!(
@cookies.merge!(
options.reject { |_, v| v.nil? }
)
else
@default_cookies_options
@cookies
end
end

Expand Down Expand Up @@ -573,7 +572,7 @@ def duplicate
c.default_format = default_format
c.default_charset = default_charset
c.default_headers = default_headers.dup
c.default_cookies_options = default_cookies_options.dup
c.cookies = cookies.dup
end
end

Expand All @@ -592,15 +591,15 @@ def duplicate
# @since 0.2.0
# @api private
def reset!
@handle_exceptions = true
@handled_exceptions = {}
@modules = []
@formats = DEFAULT_FORMATS.dup
@default_format = nil
@default_charset = nil
@default_headers = {}
@default_cookies_options = {}
@action_module = ::Lotus::Action
@handle_exceptions = true
@handled_exceptions = {}
@modules = []
@formats = DEFAULT_FORMATS.dup
@default_format = nil
@default_charset = nil
@default_headers = {}
@cookies = {}
@action_module = ::Lotus::Action
end

# Copy the configuration for the given action
Expand Down Expand Up @@ -636,7 +635,7 @@ def load!
attr_writer :default_format
attr_writer :default_charset
attr_writer :default_headers
attr_writer :default_cookies_options
attr_writer :cookies
end
end
end
4 changes: 2 additions & 2 deletions test/cookies_test.rb
Expand Up @@ -44,7 +44,7 @@ def include?(hash)
describe 'with default cookies' do
it 'gets default cookies' do
action = GetDefaultCookiesAction.new
action.class.configuration.default_cookies_options({
action.class.configuration.cookies({
domain: 'lotusrb.org', path: '/controller', secure: true, httponly: true
})

Expand All @@ -54,7 +54,7 @@ def include?(hash)

it "overwritten cookies' values are respected" do
action = GetOverwrittenCookiesAction.new
action.class.configuration.default_cookies_options({
action.class.configuration.cookies({
domain: 'lotusrb.org', path: '/controller', secure: true, httponly: true
})

Expand Down

0 comments on commit 0f85168

Please sign in to comment.