rails_request_id 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79d78b84ba0c49ca76b10e4449d7c5c0ad9b6d6f
4
+ data.tar.gz: 2c2bfb3b9ec906329690033587668a89d4b661c9
5
+ SHA512:
6
+ metadata.gz: 4680da2ee7e29d305359a6307af125a6c7af42867b8ab9e24552fb456a9323fb9c0d10b7eaf5edd273c4eb83e05450b7955cdd8c018e0c30d4c5dee860a52d6c
7
+ data.tar.gz: 943b3114d41f87e52c2523dc12470367d3c276bd0141611f5968c70010d7a6750caecbe95c1482f325717b1c0e762084def7260d335040c4fcaf92e445a4e966
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails_request_id
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ cache:
3
+ - bundler
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+ gem 'activesupport', '~> 4.1.1'
3
+
4
+ group :development do
5
+ gem 'rspec', '~> 3.0.0'
6
+ gem 'rspec-its', '~> 1.0.1'
7
+ gem 'rdoc', '~> 3.12'
8
+ gem 'bundler', '~> 1.0'
9
+ gem 'jeweler', '~> 2.0.1'
10
+ gem 'simplecov', '>= 0'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.1)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ descendants_tracker (0.0.4)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ diff-lcs (1.2.5)
15
+ docile (1.1.5)
16
+ faraday (0.9.0)
17
+ multipart-post (>= 1.2, < 3)
18
+ git (1.2.7)
19
+ github_api (0.11.3)
20
+ addressable (~> 2.3)
21
+ descendants_tracker (~> 0.0.1)
22
+ faraday (~> 0.8, < 0.10)
23
+ hashie (>= 1.2)
24
+ multi_json (>= 1.7.5, < 2.0)
25
+ nokogiri (~> 1.6.0)
26
+ oauth2
27
+ hashie (3.0.0)
28
+ highline (1.6.21)
29
+ i18n (0.6.9)
30
+ jeweler (2.0.1)
31
+ builder
32
+ bundler (>= 1.0)
33
+ git (>= 1.2.5)
34
+ github_api
35
+ highline (>= 1.6.15)
36
+ nokogiri (>= 1.5.10)
37
+ rake
38
+ rdoc
39
+ json (1.8.1)
40
+ jwt (1.0.0)
41
+ mini_portile (0.6.0)
42
+ minitest (5.3.5)
43
+ multi_json (1.10.1)
44
+ multi_xml (0.5.5)
45
+ multipart-post (2.0.0)
46
+ nokogiri (1.6.2.1)
47
+ mini_portile (= 0.6.0)
48
+ oauth2 (0.9.4)
49
+ faraday (>= 0.8, < 0.10)
50
+ jwt (~> 1.0)
51
+ multi_json (~> 1.3)
52
+ multi_xml (~> 0.5)
53
+ rack (~> 1.2)
54
+ rack (1.5.2)
55
+ rake (10.3.2)
56
+ rdoc (3.12.2)
57
+ json (~> 1.4)
58
+ rspec (3.0.0)
59
+ rspec-core (~> 3.0.0)
60
+ rspec-expectations (~> 3.0.0)
61
+ rspec-mocks (~> 3.0.0)
62
+ rspec-core (3.0.2)
63
+ rspec-support (~> 3.0.0)
64
+ rspec-expectations (3.0.2)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.0.0)
67
+ rspec-its (1.0.1)
68
+ rspec-core (>= 2.99.0.beta1)
69
+ rspec-expectations (>= 2.99.0.beta1)
70
+ rspec-mocks (3.0.2)
71
+ rspec-support (~> 3.0.0)
72
+ rspec-support (3.0.2)
73
+ simplecov (0.8.2)
74
+ docile (~> 1.1.0)
75
+ multi_json
76
+ simplecov-html (~> 0.8.0)
77
+ simplecov-html (0.8.0)
78
+ thread_safe (0.3.4)
79
+ tzinfo (1.2.1)
80
+ thread_safe (~> 0.1)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ activesupport (~> 4.1.1)
87
+ bundler (~> 1.0)
88
+ jeweler (~> 2.0.1)
89
+ rdoc (~> 3.12)
90
+ rspec (~> 3.0.0)
91
+ rspec-its (~> 1.0.1)
92
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Kunal Parikh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ #RailsRequestId [![Build Status](https://travis-ci.org/techthumb/rails_request_id.svg)](https://travis-ci.org/techthumb/rails_request_id)
2
+
3
+ Web requests in Rails get assigned a unique request id.
4
+ To access this id in a threadsafe manner, you can simply
5
+ ```
6
+ ::RailsRequestId.get
7
+ ```
8
+
9
+ ## Installation
10
+ Add this to your Gemfile
11
+ ```ruby
12
+ gem 'rails_request_id'
13
+ ```
14
+
15
+ ## Get in touch!
16
+ If you're using ```rails_request_id```, I'd love to hear from you. Drop me a line and tell me what you think at: ```kunal+rails_request_id@techthumb.in```
17
+
18
+ ## Contributing
19
+ It's on GitHub, you know what to do!
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = "rails_request_id"
16
+ gem.homepage = "http://github.com/techthumb/rails_request_id"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Allows access to Rails' request_id from global scope in a threadsafe manner}
19
+ gem.description = %Q{Web requests in Rails get assigned a unique request id. To access this id in a threadsafe manner, you can simply call ```RailsRequestId.get```}
20
+ gem.email = "kunal@techthumb.in"
21
+ gem.authors = ["Kunal Parikh"]
22
+ # dependencies defined in Gemfile
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
+
26
+ require 'rspec/core'
27
+ require 'rspec/core/rake_task'
28
+ RSpec::Core::RakeTask.new(:spec) do |spec|
29
+ spec.pattern = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ task :default => :spec
33
+
34
+ require 'rdoc/task'
35
+ Rake::RDocTask.new do |rdoc|
36
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
+
38
+ rdoc.rdoc_dir = 'rdoc'
39
+ rdoc.title = "rails_request_id #{version}"
40
+ rdoc.rdoc_files.include('README*')
41
+ rdoc.rdoc_files.include('lib/**/*.rb')
42
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,12 @@
1
+ require 'active_support'
2
+ require 'active_support/per_thread_registry'
3
+ module RailsRequestId
4
+ def self.get
5
+ RailsRequestId::Registry.request_id
6
+ end
7
+ end
8
+
9
+ require 'rails_request_id/registry'
10
+ require 'rails_request_id/middleware'
11
+ require 'rails_request_id/initializer'
12
+ require 'rails_request_id/railtie' if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ class ::RailsRequestId::Initializer
2
+ def self.initialize(config)
3
+ config.app_middleware.insert_after ActionDispatch::RequestId, 'RailsRequestId::Middleware'
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class ::RailsRequestId::Middleware
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def call(env)
7
+ ::RailsRequestId::Registry.request_id = env['action_dispatch.request_id']
8
+ puts ::RailsRequestId::Registry.request_id
9
+ @app.call(env)
10
+ ensure
11
+ ::RailsRequestId::Registry.request_id = nil
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class ::RailsRequestId::Railtie < ::Rails::Railtie
2
+ initializer :rails_request_id do
3
+ ::RailsRequestId::Initializer.initialize(config)
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ class ::RailsRequestId::Registry
2
+ extend ActiveSupport::PerThreadRegistry
3
+ attr_accessor :request_id
4
+ end
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: rails_request_id 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "rails_request_id"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Kunal Parikh"]
14
+ s.date = "2014-06-21"
15
+ s.description = "Web requests in Rails get assigned a unique request id. To access this id in a threadsafe manner, you can simply call ```RailsRequestId.get```"
16
+ s.email = "kunal@techthumb.in"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ ".ruby-gemset",
25
+ ".ruby-version",
26
+ ".travis.yml",
27
+ "Gemfile",
28
+ "Gemfile.lock",
29
+ "LICENSE.txt",
30
+ "README.md",
31
+ "Rakefile",
32
+ "VERSION",
33
+ "lib/rails_request_id.rb",
34
+ "lib/rails_request_id/initializer.rb",
35
+ "lib/rails_request_id/middleware.rb",
36
+ "lib/rails_request_id/railtie.rb",
37
+ "lib/rails_request_id/registry.rb",
38
+ "rails_request_id.gemspec",
39
+ "spec/middleware_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+ s.homepage = "http://github.com/techthumb/rails_request_id"
43
+ s.licenses = ["MIT"]
44
+ s.rubygems_version = "2.3.0"
45
+ s.summary = "Allows access to Rails' request_id from global scope in a threadsafe manner"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<activesupport>, ["~> 4.1.1"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 3.0.0"])
53
+ s.add_development_dependency(%q<rspec-its>, ["~> 1.0.1"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
57
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<activesupport>, ["~> 4.1.1"])
60
+ s.add_dependency(%q<rspec>, ["~> 3.0.0"])
61
+ s.add_dependency(%q<rspec-its>, ["~> 1.0.1"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
65
+ s.add_dependency(%q<simplecov>, [">= 0"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<activesupport>, ["~> 4.1.1"])
69
+ s.add_dependency(%q<rspec>, ["~> 3.0.0"])
70
+ s.add_dependency(%q<rspec-its>, ["~> 1.0.1"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
74
+ s.add_dependency(%q<simplecov>, [">= 0"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::RailsRequestId::Middleware do
4
+ let(:request_id) { SecureRandom.uuid }
5
+ let(:env) { { 'action_dispatch.request_id' => request_id } }
6
+ subject { ::RailsRequestId::Middleware.new(app).call(env) }
7
+
8
+ context 'happy days' do
9
+ let(:app) { double('app', call: nil) }
10
+ it 'sets and clears request_id in registry' do
11
+ expect(::RailsRequestId::Registry).to receive(:request_id=).with(request_id).ordered
12
+ expect(::RailsRequestId::Registry).to receive(:request_id=).with(nil).ordered
13
+ subject
14
+ end
15
+ end
16
+
17
+ context 'when an exception is raised' do
18
+ let(:app) { double('app') }
19
+ before :each do
20
+ allow(app).to receive(:call).and_raise('a test exception')
21
+ end
22
+ it 'sets and clears request_id in registry' do
23
+ expect(::RailsRequestId::Registry).to receive(:request_id=).with(request_id).ordered
24
+ expect(::RailsRequestId::Registry).to receive(:request_id=).with(nil).ordered
25
+ begin
26
+ subject
27
+ rescue
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rspec/its'
3
+ require 'rails_request_id'
4
+
5
+ RSpec.configure do |config|
6
+ config.raise_errors_for_deprecations!
7
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_request_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kunal Parikh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Web requests in Rails get assigned a unique request id. To access this
112
+ id in a threadsafe manner, you can simply call ```RailsRequestId.get```
113
+ email: kunal@techthumb.in
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ files:
120
+ - .document
121
+ - .rspec
122
+ - .ruby-gemset
123
+ - .ruby-version
124
+ - .travis.yml
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - VERSION
131
+ - lib/rails_request_id.rb
132
+ - lib/rails_request_id/initializer.rb
133
+ - lib/rails_request_id/middleware.rb
134
+ - lib/rails_request_id/railtie.rb
135
+ - lib/rails_request_id/registry.rb
136
+ - rails_request_id.gemspec
137
+ - spec/middleware_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: http://github.com/techthumb/rails_request_id
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.3.0
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Allows access to Rails' request_id from global scope in a threadsafe manner
163
+ test_files: []