Module: CookieCutter::Cookie::ClassMethods
- Defined in:
- lib/cookie_cutter/cookie.rb
Instance Attribute Summary collapse
-
#cookie_domain ⇒ Object
readonly
Returns the value of attribute cookie_domain.
-
#cookie_lifetime ⇒ Object
readonly
Returns the value of attribute cookie_lifetime.
-
#cookie_name ⇒ Object
readonly
Returns the value of attribute cookie_name.
Instance Method Summary collapse
- #add_handler(&block) ⇒ Object
- #add_options(cookie) ⇒ Object
- #attributes ⇒ Object
- #domain(domain_value) ⇒ Object
- #find(request, options = {}) ⇒ Object
- #handlers ⇒ Object
- #has_attribute(attribute_name, options = {}) ⇒ Object
- #http_only ⇒ Object (also: #httponly)
- #http_only? ⇒ Boolean (also: #httponly?)
- #is_permanent ⇒ Object
- #lifetime(seconds) ⇒ Object
- #multi_valued ⇒ Object
- #multi_valued? ⇒ Boolean
- #secure? ⇒ Boolean
- #secure_requests_only ⇒ Object
- #store_as(name) ⇒ Object
Instance Attribute Details
#cookie_domain ⇒ Object (readonly)
Returns the value of attribute cookie_domain.
19 20 21 |
# File 'lib/cookie_cutter/cookie.rb', line 19 def @cookie_domain end |
#cookie_lifetime ⇒ Object (readonly)
Returns the value of attribute cookie_lifetime.
28 29 30 |
# File 'lib/cookie_cutter/cookie.rb', line 28 def @cookie_lifetime end |
#cookie_name ⇒ Object (readonly)
Returns the value of attribute cookie_name.
12 13 14 |
# File 'lib/cookie_cutter/cookie.rb', line 12 def @cookie_name end |
Instance Method Details
#add_handler(&block) ⇒ Object
101 102 103 104 |
# File 'lib/cookie_cutter/cookie.rb', line 101 def add_handler(&block) handlers << block ensure_registered end |
#add_options(cookie) ⇒ Object
95 96 97 98 99 |
# File 'lib/cookie_cutter/cookie.rb', line 95 def () handlers.each do |handler| handler.call() end end |
#attributes ⇒ Object
110 111 112 |
# File 'lib/cookie_cutter/cookie.rb', line 110 def attributes @attributes ||= [] end |
#domain(domain_value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/cookie_cutter/cookie.rb', line 21 def domain(domain_value) @cookie_domain = domain_value add_handler do || [:domain] = domain_value end end |
#find(request, options = {}) ⇒ Object
7 8 9 10 |
# File 'lib/cookie_cutter/cookie.rb', line 7 def find(request, ={}) [:secure_request] = request.scheme == 'https' unless [:secure_request] new(request., ) end |
#handlers ⇒ Object
106 107 108 |
# File 'lib/cookie_cutter/cookie.rb', line 106 def handlers @handlers ||= [] end |
#has_attribute(attribute_name, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cookie_cutter/cookie.rb', line 78 def has_attribute(attribute_name, ={}) raise "CookieCutter value names must by symbols. #{attribute_name} is not a symbol" unless attribute_name.is_a?(Symbol) ensure_registered #make value and value= private when the cookie has one or more named values private :value, :value=, :set_value attribute = CookieAttribute.new(attribute_name, ) send :define_method, attribute_name do get_attribute_value(attribute.storage_key) end setter_method_name = "#{attribute_name.to_s}=".to_sym send :define_method, setter_method_name do |value| set_attribute_value(attribute.storage_key, value) end attributes << attribute end |
#http_only ⇒ Object Also known as: httponly
63 64 65 66 67 68 |
# File 'lib/cookie_cutter/cookie.rb', line 63 def http_only @http_only = true add_handler do || [:httponly] = true end end |
#http_only? ⇒ Boolean Also known as: httponly?
72 73 74 |
# File 'lib/cookie_cutter/cookie.rb', line 72 def http_only? @http_only ? true : false end |
#is_permanent ⇒ Object
37 38 39 40 |
# File 'lib/cookie_cutter/cookie.rb', line 37 def is_permanent twenty_years = 60 * 60 * 24 * 365.25 * 20 lifetime twenty_years end |
#lifetime(seconds) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cookie_cutter/cookie.rb', line 30 def lifetime(seconds) @cookie_lifetime = seconds add_handler do || [:expires] = (Time.now + seconds) end end |
#multi_valued ⇒ Object
55 56 57 |
# File 'lib/cookie_cutter/cookie.rb', line 55 def multi_valued @multi_valued = true end |
#multi_valued? ⇒ Boolean
59 60 61 |
# File 'lib/cookie_cutter/cookie.rb', line 59 def multi_valued? @multi_valued || attributes.any? end |
#secure? ⇒ Boolean
51 52 53 |
# File 'lib/cookie_cutter/cookie.rb', line 51 def secure? @secure ? true : false end |
#secure_requests_only ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/cookie_cutter/cookie.rb', line 42 def secure_requests_only @secure = true add_handler do || if [:secure_request] [:secure] = true end end end |
#store_as(name) ⇒ Object
14 15 16 17 |
# File 'lib/cookie_cutter/cookie.rb', line 14 def store_as(name) @cookie_name = name ensure_registered end |