lib/http/session/options/cookies_option.rb in ruby-http-session-1.0.1 vs lib/http/session/options/cookies_option.rb in ruby-http-session-2.1.0
- old
+ new
@@ -1,22 +1,42 @@
class HTTP::Session
class Options
class CookiesOption
- # @param [Hash] options
- def initialize(options)
- options =
- case options
- when nil, false then {enabled: false}
- when true then {enabled: true}
- else options
+ include Optionable
+
+ # @!attribute [r] jar
+ # @return [HTTP::CookieJar]
+ attr_reader :jar
+
+ # @param [Hash] opts
+ # @option opts [HTTP::CookieJar] :jar
+ def initialize(opts)
+ initialize_options(opts)
+
+ # CookieJar
+ @jar =
+ if enabled?
+ jar = @options[:jar]
+ lookup_jar(jar)
end
+ end
- @enabled = options.fetch(:enabled, true)
+ # @!visibility private
+ def freeze
+ super
end
- # Indicates whether or not the session cookie feature is enabled.
- def enabled?
- @enabled
+ private
+
+ def lookup_jar(jar)
+ case jar
+ when Hash
+ HTTP::CookieJar.new(**jar)
+ when nil
+ HTTP::CookieJar.new
+ else
+ jar
+ end
end
end
end
end