compressed-cookie 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  class CompressedCookie
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -19,8 +19,8 @@ class CompressedCookie
19
19
  # @param [ #[], #[]= ] cookie object (external) itself
20
20
  def initialize(cookie, write_access = false)
21
21
  @cookie = self.class.initialize_cookie_part(cookie)
22
- self.class.define_readers
23
- self.class.define_writers if write_access
22
+ self.extend readers
23
+ self.extend writers if write_access
24
24
  end
25
25
  # WRITE
26
26
  def self.write(cookie, &block)
@@ -97,17 +97,23 @@ class CompressedCookie
97
97
 
98
98
  private
99
99
 
100
- def self.define_readers
101
- compressor_keys.each do |method_name, key|
102
- define_method("#{method_name}") do
103
- @cookie[key]
100
+ def readers
101
+ keys = self.class.compressor_keys
102
+ Module.new do
103
+ keys.each_pair do |method_name, key|
104
+ define_method method_name do
105
+ @cookie[key]
106
+ end
104
107
  end
105
108
  end
106
109
  end
107
- def self.define_writers
108
- compressor_keys.each do |method_name, key|
109
- define_method("#{method_name}=") do |first_method_arg|
110
- @cookie[key] = first_method_arg
110
+ def writers
111
+ keys = self.class.compressor_keys
112
+ Module.new do
113
+ keys.each_pair do |method_name, key|
114
+ define_method "#{method_name}=" do |value|
115
+ @cookie[key] = value
116
+ end
111
117
  end
112
118
  end
113
119
  end
@@ -82,6 +82,23 @@ describe 'CompressedCookie' do
82
82
  @cookie_mock.should == ['new-foo', 'new-bar', 'new-baz']
83
83
  end
84
84
  end
85
+
86
+ describe 'limited access block methods' do
87
+ it 'should allow write access via #write' do
88
+ SimpleCookieMock.write(@cookie_mock) do |writer|
89
+ writer.one = 'new-bar'
90
+ end
91
+ @cookie_mock.should == ['foo', 'new-bar']
92
+ end
93
+ it 'should not allow write access via #read' do
94
+ lambda do
95
+ SimpleCookieMock.read(@cookie_mock) do |reader|
96
+ reader.one = 'new-bar'
97
+ end
98
+ end.should raise_error(NoMethodError)
99
+ @cookie_mock.should == ['foo', 'bar']
100
+ end
101
+ end
85
102
  end
86
103
 
87
104
  describe 'nested cookie' do
metadata CHANGED
@@ -1,34 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: compressed-cookie
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jens Bissinger
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-11-10 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2011-11-12 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: rspec
16
- requirement: &70226960847640 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
22
33
  type: :development
23
- prerelease: false
24
- version_requirements: *70226960847640
34
+ version_requirements: *id001
25
35
  description: Provides basically just a wrapper class around key-based cookie accessors
26
- email:
36
+ email:
27
37
  - mail@jens-bissinger.de
28
38
  executables: []
39
+
29
40
  extensions: []
41
+
30
42
  extra_rdoc_files: []
31
- files:
43
+
44
+ files:
32
45
  - .gitignore
33
46
  - Gemfile
34
47
  - MIT-LICENSE
@@ -40,31 +53,40 @@ files:
40
53
  - lib/compressed_cookie/version.rb
41
54
  - spec/compressed_cookie_spec.rb
42
55
  - spec/spec_helper.rb
43
- homepage: ''
56
+ has_rdoc: true
57
+ homepage: ""
44
58
  licenses: []
59
+
45
60
  post_install_message:
46
61
  rdoc_options: []
47
- require_paths:
62
+
63
+ require_paths:
48
64
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
50
66
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
75
  none: false
57
- requirements:
58
- - - ! '>='
59
- - !ruby/object:Gem::Version
60
- version: '0'
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
61
83
  requirements: []
84
+
62
85
  rubyforge_project: compressed-cookie
63
- rubygems_version: 1.8.10
86
+ rubygems_version: 1.6.2
64
87
  signing_key:
65
88
  specification_version: 3
66
89
  summary: Minimize your cookie footprint'
67
- test_files:
90
+ test_files:
68
91
  - spec/compressed_cookie_spec.rb
69
92
  - spec/spec_helper.rb
70
- has_rdoc: