cookie_cutter 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cookie_cutter/cookie.rb +14 -7
- data/lib/cookie_cutter/cookie_attribute.rb +14 -0
- data/lib/cookie_cutter/version.rb +1 -1
- data/spec/base_spec.rb +13 -0
- data/spec/support/fake_cookie_jar.rb +1 -1
- metadata +5 -4
data/lib/cookie_cutter/cookie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cookie_cutter/cookie_attribute'
|
2
|
+
|
1
3
|
module CookieCutter
|
2
4
|
module Cookie
|
3
5
|
module ClassMethods
|
@@ -55,19 +57,20 @@ module CookieCutter
|
|
55
57
|
end
|
56
58
|
alias_method :httponly?, :http_only?
|
57
59
|
|
58
|
-
def has_attribute(
|
59
|
-
raise "CookieCutter value names must by symbols. #{
|
60
|
+
def has_attribute(attribute_name, options={})
|
61
|
+
raise "CookieCutter value names must by symbols. #{attribute_name} is not a symbol" unless attribute_name.is_a?(Symbol)
|
60
62
|
#make value and value= private when the cookie has one or more named values
|
61
63
|
private :value, :value=, :set_value
|
62
64
|
|
63
|
-
|
64
|
-
send :define_method,
|
65
|
-
get_attribute_value(
|
65
|
+
attribute = CookieAttribute.new(attribute_name, options)
|
66
|
+
send :define_method, attribute_name do
|
67
|
+
get_attribute_value(attribute.storage_key)
|
66
68
|
end
|
67
|
-
setter_method_name = "#{
|
69
|
+
setter_method_name = "#{attribute_name.to_s}=".to_sym
|
68
70
|
send :define_method, setter_method_name do |value|
|
69
|
-
set_attribute_value(
|
71
|
+
set_attribute_value(attribute.storage_key, value)
|
70
72
|
end
|
73
|
+
attributes << attribute
|
71
74
|
end
|
72
75
|
|
73
76
|
def add_options(cookie)
|
@@ -83,6 +86,10 @@ module CookieCutter
|
|
83
86
|
def handlers
|
84
87
|
@handlers ||= []
|
85
88
|
end
|
89
|
+
|
90
|
+
def attributes
|
91
|
+
@attributes ||= []
|
92
|
+
end
|
86
93
|
end
|
87
94
|
|
88
95
|
def self.included(klass)
|
data/spec/base_spec.rb
CHANGED
@@ -154,5 +154,18 @@ describe CookieCutter::Base do
|
|
154
154
|
multi_valued_cookie.value2 = "myval2"
|
155
155
|
cookie_jar[:mvc][:val2].should == "myval2"
|
156
156
|
end
|
157
|
+
describe 'attribute metadata' do
|
158
|
+
it "should provide attributes array" do
|
159
|
+
MultiValuedCookie.attributes.length.should == 2
|
160
|
+
end
|
161
|
+
it "should provide each attribute name" do
|
162
|
+
MultiValuedCookie.attributes.find{|a| a.name == :value1}.should_not be_nil
|
163
|
+
MultiValuedCookie.attributes.find{|a| a.name == :value2}.should_not be_nil
|
164
|
+
end
|
165
|
+
it "should provide each attribute storage key as a symbol" do
|
166
|
+
MultiValuedCookie.attributes.find{|a| a.name == :value1}.storage_key.should == :value1
|
167
|
+
MultiValuedCookie.attributes.find{|a| a.name == :value2}.storage_key.should == :val2
|
168
|
+
end
|
169
|
+
end
|
157
170
|
end
|
158
171
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookie_cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/cookie_cutter.rb
|
78
78
|
- lib/cookie_cutter/base.rb
|
79
79
|
- lib/cookie_cutter/cookie.rb
|
80
|
+
- lib/cookie_cutter/cookie_attribute.rb
|
80
81
|
- lib/cookie_cutter/version.rb
|
81
82
|
- spec/base_spec.rb
|
82
83
|
- spec/support/fake_cookie_jar.rb
|
@@ -94,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
95
|
version: '0'
|
95
96
|
segments:
|
96
97
|
- 0
|
97
|
-
hash:
|
98
|
+
hash: 892397825148305271
|
98
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
100
|
none: false
|
100
101
|
requirements:
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
segments:
|
105
106
|
- 0
|
106
|
-
hash:
|
107
|
+
hash: 892397825148305271
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
110
|
rubygems_version: 1.8.24
|