request 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5609a4d356f4253c73bbfd2b6bdcf67e736a20b
4
+ data.tar.gz: 97315e65a35520a162dc480632522570d5239c7d
5
+ SHA512:
6
+ metadata.gz: 5321734f4c8547c2664cf3332537734ba77f12f10659b2a7b003c335b43a1d77c0432737f9dc6c8e1ae7cd817e52e619d640519660c3dca44a1009e05d7e8974
7
+ data.tar.gz: f3b0c427a5866920d8aa72a2c2b2d92bd28f026e4025a0c485fb75311c2258761d75ff964afdaadfa207b47425b014f539b4a69a9613730f28631448c192f98e
@@ -0,0 +1,4 @@
1
+ ---
2
+ test:
3
+ override:
4
+ - bundle exec rake ci
@@ -1,17 +1,13 @@
1
1
  language: ruby
2
2
  script: 'bundle exec rake spec'
3
3
  rvm:
4
- - ree
5
- - 1.8.7
6
4
  - 1.9.2
7
5
  - 1.9.3
8
6
  - 2.0.0
9
7
  - ruby-head
10
- - jruby-18mode
11
8
  - jruby-19mode
12
9
  - jruby-head
13
- - rbx-18mode
14
10
  - rbx-19mode
15
- notifications:
16
- email:
17
- - mbj@seonic.net
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
@@ -1,3 +1,7 @@
1
+ # v0.0.4 2013-05-21
2
+
3
+ - Fix equalizing of Request::Rack
4
+
1
5
  # v0.0.3 2013-05-21
2
6
 
3
7
  - Regression in Request::Rack#rack_env
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
5
+ gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
6
6
  eval File.read('Gemfile.devtools')
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  group :development do
4
- gem 'rake', '~> 10.0.4'
4
+ gem 'rake', '~> 10.1.0'
5
5
  gem 'rspec', '~> 2.13.0'
6
6
  gem 'yard', '~> 0.8.6.1'
7
7
  end
@@ -11,12 +11,12 @@ group :yard do
11
11
  end
12
12
 
13
13
  group :guard do
14
- gem 'guard', '~> 1.8.0'
14
+ gem 'guard', '~> 1.8.1'
15
15
  gem 'guard-bundler', '~> 1.0.0'
16
- gem 'guard-rspec', '~> 2.5.4'
16
+ gem 'guard-rspec', '~> 3.0.2'
17
17
 
18
18
  # file system change event handling
19
- gem 'listen', '~> 1.0.2'
19
+ gem 'listen', '~> 1.2.2'
20
20
  gem 'rb-fchange', '~> 0.0.6', :require => false
21
21
  gem 'rb-fsevent', '~> 0.9.3', :require => false
22
22
  gem 'rb-inotify', '~> 0.9.0', :require => false
@@ -28,20 +28,20 @@ group :guard do
28
28
  end
29
29
 
30
30
  group :metrics do
31
- gem 'backports', '~> 3.3', '>= 3.3.0'
32
- gem 'coveralls', '~> 0.6.6'
33
- gem 'flay', '~> 2.2.0'
34
- gem 'flog', '~> 4.0.0'
35
- gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
- gem 'simplecov', '~> 0.7.1'
37
- gem 'yardstick', '~> 0.9.6'
31
+ gem 'backports', '~> 3.3', '>= 3.3.2'
32
+ gem 'coveralls', '~> 0.6.7'
33
+ gem 'flay', '~> 2.3.0'
34
+ gem 'flog', '~> 4.1.0'
35
+ gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
+ gem 'simplecov', '~> 0.7.1'
37
+ gem 'yardstick', '~> 0.9.6'
38
38
 
39
39
  platforms :ruby_19 do
40
40
  gem 'yard-spellcheck', '~> 0.1.5'
41
41
  end
42
42
 
43
- platforms :mri_19, :rbx do
44
- gem 'mutant', '~> 0.2.20'
43
+ platforms :ruby_19, :ruby_20 do
44
+ gem 'mutant', '~> 0.3.0.beta4'
45
45
  end
46
46
 
47
47
  platforms :rbx do
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 12
3
- total_score: 77
3
+ total_score: 74
@@ -22,7 +22,8 @@ UncommunicativeMethodName:
22
22
  - !ruby/regexp /[A-Z]/
23
23
  LongParameterList:
24
24
  max_params: 2
25
- exclude: []
25
+ exclude:
26
+ - Request::Rack#self.accessor # 3 params
26
27
  enabled: true
27
28
  overrides: {}
28
29
  FeatureEnvy:
@@ -10,7 +10,7 @@ require 'securerandom'
10
10
  class Request
11
11
 
12
12
  KEYS = %W(
13
- path_info protocol port request_method
13
+ path_info protocol port request_method
14
14
  host if_modified_since query_params query_params_hash
15
15
  query_string content_length content_type body
16
16
  ).map(&:to_sym).freeze
@@ -133,18 +133,6 @@ class Request
133
133
  "#{root_uri}#{path}"
134
134
  end
135
135
 
136
- # Return routed request
137
- #
138
- # @param [Hash] params
139
- #
140
- # @return [Request::Routed]
141
- #
142
- # @api private
143
- #
144
- def route(params)
145
- Routed.new(self, params)
146
- end
147
-
148
136
  # Return root uri
149
137
  #
150
138
  # @return [String]
@@ -178,6 +166,5 @@ end
178
166
 
179
167
  require 'request/key'
180
168
  require 'request/rack'
181
- require 'request/routed'
182
169
  require 'request/method'
183
170
  require 'request/protocol'
@@ -1,7 +1,6 @@
1
1
  class Request
2
2
  # Rack request
3
3
  class Rack < self
4
- include Concord::Public.new(:rack_env)
5
4
 
6
5
  SERVER_PORT = Key.new('SERVER_PORT')
7
6
  REQUEST_METHOD = Key.new('REQUEST_METHOD')
@@ -9,6 +8,29 @@ class Request
9
8
  IF_MODIFIED_SINCE = Key.new('HTTP_IF_MODIFIED_SINCE')
10
9
  CONTENT_LENGTH = Key.new('CONTENT_LENGTH')
11
10
 
11
+ # Error raised when an invalid rack env key is accessed
12
+ InvalidKeyError = Class.new(RuntimeError)
13
+
14
+ # Initialize object
15
+ #
16
+ # @param [Hash] rack_env
17
+ #
18
+ # @return [undefined]
19
+ #
20
+ # @api private
21
+ #
22
+ def initialize(rack_env)
23
+ @rack_env = rack_env
24
+ end
25
+
26
+ # Return rack env
27
+ #
28
+ # @return [Hash]
29
+ #
30
+ # @api private
31
+ #
32
+ attr_reader :rack_env
33
+
12
34
  # Declare accessor
13
35
  #
14
36
  # @param [Symbol] name
@@ -18,11 +40,12 @@ class Request
18
40
  #
19
41
  # @api private
20
42
  #
21
- def self.accessor(name, key)
43
+ def self.accessor(name, key, *args)
22
44
  define_method(name) do
23
- access(key)
45
+ access(key, *args)
24
46
  end
25
47
  end
48
+ private_class_method :accessor
26
49
 
27
50
  # Return http port
28
51
  #
@@ -57,6 +80,8 @@ class Request
57
80
  end
58
81
  memoize :request_method
59
82
 
83
+ CONTENT_LENGTH_REGEXP = /\A[0-9]+\z/.freeze
84
+
60
85
  # Return content length
61
86
  #
62
87
  # @return [Fixnum]
@@ -64,8 +89,17 @@ class Request
64
89
  # @api private
65
90
  #
66
91
  def content_length
67
- access(CONTENT_LENGTH).to_i(10)
92
+ value = @rack_env.fetch(CONTENT_LENGTH) do
93
+ return 0
94
+ end
95
+
96
+ unless value =~ CONTENT_LENGTH_REGEXP
97
+ raise InvalidKeyError, 'invalid content length'
98
+ end
99
+
100
+ value.to_i
68
101
  end
102
+ memoize :content_length
69
103
 
70
104
  # Return query params
71
105
  #
@@ -98,11 +132,11 @@ class Request
98
132
  end
99
133
  memoize :if_modified_since
100
134
 
101
- accessor(:path_info, Key.new('PATH_INFO') )
102
- accessor(:host, Key.new('SERVER_NAME') )
103
- accessor(:query_string, Key.new('QUERY_STRING'))
104
- accessor(:content_type, Key.new('CONTENT_TYPE'))
105
- accessor(:body, Key.new('rack.input'))
135
+ accessor(:path_info, Key.new('PATH_INFO') )
136
+ accessor(:host, Key.new('SERVER_NAME') )
137
+ accessor(:query_string, Key.new('QUERY_STRING') )
138
+ accessor(:content_type, Key.new('CONTENT_TYPE'), nil)
139
+ accessor(:body, Key.new('rack.input') )
106
140
 
107
141
  private
108
142
 
@@ -114,8 +148,9 @@ class Request
114
148
  #
115
149
  # @api private
116
150
  #
117
- def access(key)
118
- @rack_env.fetch(key)
151
+ def access(key, *args)
152
+ @rack_env.fetch(key, *args)
119
153
  end
120
- end
121
- end
154
+
155
+ end # Rack
156
+ end # Request
@@ -2,9 +2,9 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'request'
5
- gem.version = '0.0.3'
5
+ gem.version = '0.0.4'
6
6
  gem.authors = [ 'Markus Schirp' ]
7
- gem.email = [ 'mbj@seonic.net' ]
7
+ gem.email = [ 'mbj@schirp-dso.com' ]
8
8
  gem.description = 'HTTP request porofication'
9
9
  gem.summary = gem.description
10
10
  gem.homepage = 'https://github.com/mbj/response'
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_dependency('backports', [ '~> 3.0', '>= 3.0.3' ])
18
18
  gem.add_dependency('concord', '~> 0.1.0')
19
- gem.add_dependency('ice_nine', '~> 0.7.0')
20
- gem.add_dependency('adamantium', '~> 0.0.7')
19
+ gem.add_dependency('ice_nine', '~> 0.8.0')
20
+ gem.add_dependency('adamantium', '~> 0.0.8')
21
21
  gem.add_dependency('equalizer', '~> 0.0.5')
22
22
  gem.add_dependency('abstract_type', '~> 0.0.5')
23
23
  end
@@ -1,4 +1,4 @@
1
- shared_examples_for 'a rack env accessor' do
1
+ shared = proc do
2
2
  let(:rack_key_value) { :Value }
3
3
 
4
4
  let(:default_env) do
@@ -11,9 +11,13 @@ shared_examples_for 'a rack env accessor' do
11
11
  }
12
12
  end
13
13
 
14
- let(:expected_value) { rack_key_value }
14
+ let(:expected_value) { rack_key_value }
15
+ let(:env) { default_env.merge(rack_key => rack_key_value) }
16
+ let(:object) { described_class.new(env) }
17
+ end
15
18
 
16
- let(:env) { default_env.merge(rack_key => rack_key_value) }
19
+ shared_examples_for 'a rack env accessor' do
20
+ instance_eval(&shared)
17
21
 
18
22
  it { should eql(expected_value) }
19
23
 
@@ -22,3 +26,11 @@ shared_examples_for 'a rack env accessor' do
22
26
  env.frozen?.should be(false)
23
27
  end
24
28
  end
29
+
30
+ shared_examples_for 'an invalid rack env accessor' do
31
+ instance_eval(&shared)
32
+
33
+ it 'should raise error' do
34
+ expect { subject }.to raise_error(Request::Rack::InvalidKeyError, expected_message)
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Request::Protocol, '.get' do
4
+ let(:object) { described_class }
5
+
6
+ subject { object.get(input) }
7
+
8
+ context 'with "http"' do
9
+ let(:input) { 'http' }
10
+ it { should eql(Request::Protocol::HTTP) }
11
+ end
12
+
13
+ context 'with "https"' do
14
+ let(:input) { 'https' }
15
+ it { should eql(Request::Protocol::HTTPS) }
16
+ end
17
+
18
+ context 'with "ftp"' do
19
+ let(:input) { 'ftp' }
20
+ it 'should raise error' do
21
+ expect { subject }.to raise_error(KeyError, 'key not found: "ftp"')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Request::Rack, '#content_length' do
4
+ subject { object.content_length }
5
+
6
+ let(:rack_key) { 'CONTENT_LENGTH'}
7
+
8
+ context 'with decimal positive integer' do
9
+ it_should_behave_like 'a rack env accessor' do
10
+
11
+ let(:rack_key_value) { '10' }
12
+ let(:expected_value) { 10 }
13
+
14
+ end
15
+ end
16
+
17
+ context 'with decimal negative integer' do
18
+
19
+ it_should_behave_like 'an invalid rack env accessor' do
20
+
21
+ let(:rack_key_value) { '-10' }
22
+ let(:expected_message) { 'invalid content length' }
23
+
24
+ end
25
+ end
26
+
27
+ context 'other garbadge' do
28
+
29
+ it_should_behave_like 'an invalid rack env accessor' do
30
+
31
+ let(:rack_key_value) { '0asd2431' }
32
+ let(:expected_message) { 'invalid content length' }
33
+
34
+ end
35
+ end
36
+
37
+ context 'when CONTENT_LENGTH key is not present' do
38
+
39
+ let(:rack_key) { 'SOMETHING_OTHER' }
40
+
41
+ it_should_behave_like 'a rack env accessor' do
42
+
43
+ let(:expected_value) { 0 }
44
+
45
+ end
46
+ end
47
+ end
@@ -11,8 +11,6 @@ describe Request::Rack, '#protocol' do
11
11
  let(:rack_key_value) { protocol.name }
12
12
  let(:expected_value) { protocol }
13
13
 
14
- #let(:expected_method)
15
-
16
14
  end
17
15
  end
18
16
  end
@@ -6,7 +6,7 @@ describe Request::Rack, '#query_string' do
6
6
  it_should_behave_like 'a rack env accessor' do
7
7
 
8
8
  let(:object) { described_class.new(env) }
9
- let(:rack_key) { 'QUERY_STRING' }
9
+ let(:rack_key) { 'QUERY_STRING' }
10
10
 
11
11
  end
12
12
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Request::Rack, '#rack_env' do
4
- let(:object) { described_class.new(rack_env) }
5
-
6
4
  subject { object.rack_env }
7
5
 
6
+ let(:object) { described_class.new(rack_env) }
7
+
8
8
  let(:rack_env) { mock('Rack Env') }
9
9
 
10
10
  it { should be(rack_env) }
11
11
 
12
- it_should_behave_like 'a command method'
12
+ it_should_behave_like 'an idempotent method'
13
13
  end
@@ -11,8 +11,6 @@ describe Request::Rack, '#request_method' do
11
11
  let(:rack_key_value) { method.verb }
12
12
  let(:expected_value) { method }
13
13
 
14
- #let(:expected_method)
15
-
16
14
  end
17
15
  end
18
16
  end
metadata CHANGED
@@ -1,42 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Markus Schirp
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-07-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: backports
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
- - - ! '>='
20
+ - - '>='
23
21
  - !ruby/object:Gem::Version
24
22
  version: 3.0.3
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - ~>
31
28
  - !ruby/object:Gem::Version
32
29
  version: '3.0'
33
- - - ! '>='
30
+ - - '>='
34
31
  - !ruby/object:Gem::Version
35
32
  version: 3.0.3
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: concord
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
37
  - - ~>
42
38
  - !ruby/object:Gem::Version
@@ -44,7 +40,6 @@ dependencies:
44
40
  type: :runtime
45
41
  prerelease: false
46
42
  version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
43
  requirements:
49
44
  - - ~>
50
45
  - !ruby/object:Gem::Version
@@ -52,39 +47,34 @@ dependencies:
52
47
  - !ruby/object:Gem::Dependency
53
48
  name: ice_nine
54
49
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
50
  requirements:
57
51
  - - ~>
58
52
  - !ruby/object:Gem::Version
59
- version: 0.7.0
53
+ version: 0.8.0
60
54
  type: :runtime
61
55
  prerelease: false
62
56
  version_requirements: !ruby/object:Gem::Requirement
63
- none: false
64
57
  requirements:
65
58
  - - ~>
66
59
  - !ruby/object:Gem::Version
67
- version: 0.7.0
60
+ version: 0.8.0
68
61
  - !ruby/object:Gem::Dependency
69
62
  name: adamantium
70
63
  requirement: !ruby/object:Gem::Requirement
71
- none: false
72
64
  requirements:
73
65
  - - ~>
74
66
  - !ruby/object:Gem::Version
75
- version: 0.0.7
67
+ version: 0.0.8
76
68
  type: :runtime
77
69
  prerelease: false
78
70
  version_requirements: !ruby/object:Gem::Requirement
79
- none: false
80
71
  requirements:
81
72
  - - ~>
82
73
  - !ruby/object:Gem::Version
83
- version: 0.0.7
74
+ version: 0.0.8
84
75
  - !ruby/object:Gem::Dependency
85
76
  name: equalizer
86
77
  requirement: !ruby/object:Gem::Requirement
87
- none: false
88
78
  requirements:
89
79
  - - ~>
90
80
  - !ruby/object:Gem::Version
@@ -92,7 +82,6 @@ dependencies:
92
82
  type: :runtime
93
83
  prerelease: false
94
84
  version_requirements: !ruby/object:Gem::Requirement
95
- none: false
96
85
  requirements:
97
86
  - - ~>
98
87
  - !ruby/object:Gem::Version
@@ -100,7 +89,6 @@ dependencies:
100
89
  - !ruby/object:Gem::Dependency
101
90
  name: abstract_type
102
91
  requirement: !ruby/object:Gem::Requirement
103
- none: false
104
92
  requirements:
105
93
  - - ~>
106
94
  - !ruby/object:Gem::Version
@@ -108,14 +96,13 @@ dependencies:
108
96
  type: :runtime
109
97
  prerelease: false
110
98
  version_requirements: !ruby/object:Gem::Requirement
111
- none: false
112
99
  requirements:
113
100
  - - ~>
114
101
  - !ruby/object:Gem::Version
115
102
  version: 0.0.5
116
103
  description: HTTP request porofication
117
104
  email:
118
- - mbj@seonic.net
105
+ - mbj@schirp-dso.com
119
106
  executables: []
120
107
  extensions: []
121
108
  extra_rdoc_files:
@@ -123,6 +110,7 @@ extra_rdoc_files:
123
110
  - README.md
124
111
  - TODO
125
112
  files:
113
+ - .circle.yml
126
114
  - .gitignore
127
115
  - .rspec
128
116
  - .travis.yml
@@ -146,11 +134,12 @@ files:
146
134
  - lib/request/method.rb
147
135
  - lib/request/protocol.rb
148
136
  - lib/request/rack.rb
149
- - lib/request/routed.rb
150
137
  - request.gemspec
151
138
  - spec/shared/rack_env_accessor_behavior.rb
152
139
  - spec/spec_helper.rb
153
140
  - spec/unit/request/key/hash_spec.rb
141
+ - spec/unit/request/protocol/class_methods/get_spec.rb
142
+ - spec/unit/request/rack/content_length_spec.rb
154
143
  - spec/unit/request/rack/host_spec.rb
155
144
  - spec/unit/request/rack/if_modified_since_spec.rb
156
145
  - spec/unit/request/rack/path_info_spec.rb
@@ -161,27 +150,26 @@ files:
161
150
  - spec/unit/request/rack/request_method_spec.rb
162
151
  homepage: https://github.com/mbj/response
163
152
  licenses: []
153
+ metadata: {}
164
154
  post_install_message:
165
155
  rdoc_options: []
166
156
  require_paths:
167
157
  - lib
168
158
  required_ruby_version: !ruby/object:Gem::Requirement
169
- none: false
170
159
  requirements:
171
- - - ! '>='
160
+ - - '>='
172
161
  - !ruby/object:Gem::Version
173
162
  version: '0'
174
163
  required_rubygems_version: !ruby/object:Gem::Requirement
175
- none: false
176
164
  requirements:
177
- - - ! '>='
165
+ - - '>='
178
166
  - !ruby/object:Gem::Version
179
167
  version: '0'
180
168
  requirements: []
181
169
  rubyforge_project:
182
- rubygems_version: 1.8.23
170
+ rubygems_version: 2.0.2
183
171
  signing_key:
184
- specification_version: 3
172
+ specification_version: 4
185
173
  summary: HTTP request porofication
186
174
  test_files: []
187
175
  has_rdoc:
@@ -1,20 +0,0 @@
1
- class Request
2
- # A routed request with routing params
3
- #
4
- # FIXME: I do not like this, need to come up with something much better!
5
- #
6
- # Violates LSP.
7
- #
8
- # Remove this once "Dispatch" class in Joy is ready.
9
- #
10
- class Routed < self
11
- include Concord::Public.new(:request, :routing_params)
12
-
13
- METHODS.each do |name|
14
- define_method(name) do
15
- @request.public_send(name)
16
- end
17
- end
18
- end
19
- end
20
-