cookie_cutter 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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(value_name, options={})
59
- raise "CookieCutter value names must by symbols. #{value_name} is not a symbol" unless value_name.is_a?(Symbol)
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
- value_key = (options[:store_as] || value_name).to_sym
64
- send :define_method, value_name do
65
- get_attribute_value(value_key)
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 = "#{value_name.to_s}=".to_sym
69
+ setter_method_name = "#{attribute_name.to_s}=".to_sym
68
70
  send :define_method, setter_method_name do |value|
69
- set_attribute_value(value_key, 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)
@@ -0,0 +1,14 @@
1
+ module CookieCutter
2
+ class CookieAttribute
3
+ attr_reader :name
4
+
5
+ def initialize(name, options)
6
+ @name = name
7
+ @options = options
8
+ end
9
+
10
+ def storage_key
11
+ (@options[:store_as] || @name).to_sym
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module CookieCutter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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
@@ -12,7 +12,7 @@ class FakeCookieJar
12
12
  @cookies[name] = value
13
13
  end
14
14
 
15
- def delete(name)
15
+ def delete(name, options)
16
16
  @deleted_cookies << name
17
17
  end
18
18
 
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.1.1
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-07 00:00:00.000000000 Z
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: 4187544879423060656
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: 4187544879423060656
107
+ hash: 892397825148305271
107
108
  requirements: []
108
109
  rubyforge_project:
109
110
  rubygems_version: 1.8.24