Module: CookieCutter::Cookie::ClassMethods

Defined in:
lib/cookie_cutter/cookie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute cookie_domain.



19
20
21
# File 'lib/cookie_cutter/cookie.rb', line 19

def cookie_domain
  @cookie_domain
end

Returns the value of attribute cookie_lifetime.



28
29
30
# File 'lib/cookie_cutter/cookie.rb', line 28

def cookie_lifetime
  @cookie_lifetime
end

Returns the value of attribute cookie_name.



12
13
14
# File 'lib/cookie_cutter/cookie.rb', line 12

def cookie_name
  @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 add_options(cookie)
  handlers.each do |handler|
    handler.call(cookie)
  end
end

#attributesObject



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 |cookie|
    cookie[:domain] = domain_value
  end
end

#find(request, options = {}) ⇒ Object



7
8
9
10
# File 'lib/cookie_cutter/cookie.rb', line 7

def find(request, options={})
  options[:secure_request] = request.scheme == 'https' unless options[:secure_request]
  new(request.cookie_jar, options)
end

#handlersObject



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, options={})
  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, options)
  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_onlyObject 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 |cookie|
    cookie[:httponly] = true
  end
end

#http_only?Boolean Also known as: httponly?

Returns:

  • (Boolean)


72
73
74
# File 'lib/cookie_cutter/cookie.rb', line 72

def http_only?
  @http_only ? true : false
end

#is_permanentObject



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 |cookie|
    cookie[:expires] = (Time.now + seconds)
  end
end

#multi_valuedObject



55
56
57
# File 'lib/cookie_cutter/cookie.rb', line 55

def multi_valued
  @multi_valued = true
end

#multi_valued?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cookie_cutter/cookie.rb', line 59

def multi_valued?
  @multi_valued || attributes.any?
end

#secure?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cookie_cutter/cookie.rb', line 51

def secure?
  @secure ? true : false
end

#secure_requests_onlyObject



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 |cookie|
    if cookie[:secure_request]
      cookie[: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