rack-request_time 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/lib/rack-request_time.rb +23 -0
- data/rack-request_time.gemspec +20 -0
- data/spec/rack-request_time_spec.rb +52 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95225213d8f39ed6b36bea17300d34efe91fa802
|
4
|
+
data.tar.gz: f994e1cdd59b0d124f39586e42517a0e5cd8fc4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11fcf7b4c03488f60f6ac89db1e94fc9bd1d8759b5358ef3c542dee7bd7a242db31d577c7701a57f3d22ec14c2bf2bb3fb40b787093d4bdfa05b8899499bb256
|
7
|
+
data.tar.gz: 2d858f54bee74cfd1c5af3c105f49d36d680b1096136f07eb3c5bcbcc1c105b5cdd6627093aacf51ad3a782f45c6db91776b4007bf74f97bd51ad825c5e5d6af
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rack-request_time (0.0.1)
|
5
|
+
activesupport
|
6
|
+
rack
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.2.9)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
multi_json (~> 1.0)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
i18n (0.6.1)
|
16
|
+
multi_json (1.3.7)
|
17
|
+
rack (1.4.1)
|
18
|
+
rspec (2.12.0)
|
19
|
+
rspec-core (~> 2.12.0)
|
20
|
+
rspec-expectations (~> 2.12.0)
|
21
|
+
rspec-mocks (~> 2.12.0)
|
22
|
+
rspec-core (2.12.0)
|
23
|
+
rspec-expectations (2.12.0)
|
24
|
+
diff-lcs (~> 1.1.3)
|
25
|
+
rspec-mocks (2.12.0)
|
26
|
+
timecop (0.5.3)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
rack-request_time!
|
33
|
+
rspec
|
34
|
+
timecop
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 onk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Rack::RequestTime
|
2
|
+
========================================================================
|
3
|
+
|
4
|
+
Rack::RequestTime is a Rack middleware for using consistent time in request.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
------------------------------------------------------------------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "rack-request_time"
|
13
|
+
```
|
14
|
+
|
15
|
+
Add Rack::RequestTime in your application's Rack middleware stack:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# sinatra
|
19
|
+
use Rack::RequestTime
|
20
|
+
|
21
|
+
# rails
|
22
|
+
config.middleware.use Rack::RequestTime
|
23
|
+
```
|
24
|
+
|
25
|
+
Write application code using `Rack::RequestTime.current` instead of `Time.current`
|
26
|
+
|
27
|
+
Author
|
28
|
+
------------------------------------------------------------------------
|
29
|
+
|
30
|
+
onk <takafumi.onaka@gmail.com> (@onk)
|
31
|
+
|
32
|
+
License
|
33
|
+
------------------------------------------------------------------------
|
34
|
+
|
35
|
+
Licensed under the MIT license.
|
36
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class RequestTime
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
self.class.current = Time.current
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.current
|
15
|
+
Thread.current[:_rack_request_time]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.current=(now)
|
19
|
+
Thread.current[:_rack_request_time] = now
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "rack-request_time"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.authors = ["onk"]
|
5
|
+
gem.email = ["takafumi.onaka@gmail.com"]
|
6
|
+
gem.description = %q{Rack middleware for using consistent time in request.}
|
7
|
+
gem.summary = %q{Rack::RequestTime is a Rack middleware for using consistent time in request.}
|
8
|
+
gem.homepage = "https://github.com/onk/rack-request_time"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($/)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
|
15
|
+
gem.add_dependency "rack"
|
16
|
+
gem.add_dependency "activesupport"
|
17
|
+
gem.add_development_dependency "rspec"
|
18
|
+
gem.add_development_dependency "timecop"
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rack-request_time"
|
2
|
+
require "rack/lint"
|
3
|
+
require "rack/mock"
|
4
|
+
require "timecop"
|
5
|
+
|
6
|
+
describe Rack::RequestTime do
|
7
|
+
let(:base_app) do
|
8
|
+
lambda do |env|
|
9
|
+
[200, {"Content-Type" => "text/plain"}, "HELLO"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
let(:app) { Rack::Lint.new Rack::RequestTime.new(base_app) }
|
13
|
+
|
14
|
+
def request
|
15
|
+
app.call Rack::MockRequest.env_for
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".current" do
|
19
|
+
before do
|
20
|
+
@requested_at = Timecop.freeze(Time.current)
|
21
|
+
request
|
22
|
+
end
|
23
|
+
subject { Rack::RequestTime.current }
|
24
|
+
it { should == @requested_at }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "called twice" do
|
28
|
+
before do
|
29
|
+
@first_requested_at = Timecop.freeze(Time.current)
|
30
|
+
request
|
31
|
+
@second_requested_at = Timecop.freeze(@first_requested_at + 1)
|
32
|
+
request
|
33
|
+
end
|
34
|
+
subject { Rack::RequestTime.current }
|
35
|
+
it { should == @second_requested_at }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'multithread' do
|
39
|
+
before do
|
40
|
+
@first_requested_at = Timecop.freeze(Time.current)
|
41
|
+
request
|
42
|
+
|
43
|
+
Thread.new {
|
44
|
+
@second_requested_at = Timecop.freeze(@first_requested_at + 1)
|
45
|
+
request
|
46
|
+
}.join
|
47
|
+
end
|
48
|
+
subject { Rack::RequestTime.current }
|
49
|
+
it { should == @first_requested_at }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-request_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- onk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Rack middleware for using consistent time in request.
|
70
|
+
email:
|
71
|
+
- takafumi.onaka@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- CHANGELOG.md
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/rack-request_time.rb
|
84
|
+
- rack-request_time.gemspec
|
85
|
+
- spec/rack-request_time_spec.rb
|
86
|
+
homepage: https://github.com/onk/rack-request_time
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Rack::RequestTime is a Rack middleware for using consistent time in request.
|
109
|
+
test_files:
|
110
|
+
- spec/rack-request_time_spec.rb
|
111
|
+
has_rdoc:
|