store_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: 702a1513bf551bd5bbfe518ae97102264aced8ab
4
+ data.tar.gz: e44507d7f4a3cbf94e1066de1483048005071354
5
+ SHA512:
6
+ metadata.gz: e993c38a997be8dba0b3457a29530467c2b8d790ecced914249dcc2a3a732fb1e1b4ae26a710fb92fdd81ab13f82138339d614f509b533a8774ed282b26a7c70
7
+ data.tar.gz: b94ddc115950f240e15410ad15909c78c8ea4ec0bcf56fdcb4189347ec124539f17cae0ec376fdeeed2fa662e0fa67c60a8fe53b2a08fb95acc3b53464a06808
data/.codeclimate.yml ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ engines:
3
+ reek:
4
+ enabled: true
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ ruby:
10
+ mass_threshold: 26
11
+ fixme:
12
+ enabled: true
13
+ checks:
14
+ TODO:
15
+ enabled: false
16
+ rubocop:
17
+ enabled: true
18
+ ratings:
19
+ paths:
20
+ - Gemfile.lock
21
+ - '**.erb'
22
+ - '**.rb'
23
+ exclude_paths:
24
+ - spec/
25
+ - config/
26
+ - db/
27
+ - vendor/
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+ # rspec failure tracking
12
+ .rspec_status
data/.reek ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ TooManyStatements:
3
+ enabled: true
4
+ max_statements: 10
5
+
6
+ # Directories below will not be scanned at all
7
+ exclude_paths:
8
+ - spec
9
+
10
+ LongParameterList:
11
+ max_params: 4
12
+
13
+ IrresponsibleModule:
14
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'spec/**/*'
4
+
5
+ Metrics/LineLength:
6
+ Max: 100
7
+
8
+ Metrics/MethodLength:
9
+ CountComments: false # count full line comments?
10
+ Max: 15
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - '*.gemspec'
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ # fix for codeclimate
20
+ Style/PercentLiteralDelimiters:
21
+ PreferredDelimiters:
22
+ default: ()
23
+ '%i': '[]'
24
+ '%w': '[]'
25
+ '%W': '[]'
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.2
7
+ - 2.2.3
8
+ - 2.3.1
9
+ - 2.4.1
10
+
11
+ addons:
12
+ code_climate:
13
+ repo_token: 682975bb1f8c2c0c4b854034c70744758c50c832e28c563d8a7e7bdabf821e34
14
+
15
+ before_install: gem install bundler -v 1.15.3
16
+
17
+ cache:
18
+ - bundler
19
+
20
+ script:
21
+ - bundle exec rake
22
+
23
+ after_success:
24
+ - bundle exec codeclimate-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## [0.1.0](https://github.com/SparkHub/gs-store-reqeust-id/tree/v0.1.0) (2017-08-11)
2
+
3
+ **Implemented enhancements:**
4
+ - Initial version :tada: ([mchaisse](https://github.com/mchaisse))
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sysadmin@guidespark.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in store_request_id.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'reek', RUBY_VERSION >= '2.1.0' ? '>= 4' : '< 4', require: false
8
+ gem 'rubocop', RUBY_VERSION >= '2.0.0' ? '>= 0.48.1' : '< 0.48.1', require: false
9
+ end
10
+
11
+ group :test do
12
+ gem 'codeclimate-test-reporter', require: false if RUBY_VERSION >= '2.0'
13
+ gem 'simplecov', require: false
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Maxime Chaisse-Leal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ [![Gem Version](https://badge.fury.io/rb/gs-store-request-id.svg)](http://badge.fury.io/rb/gs-store-request-id)
2
+ [![Build Status](https://travis-ci.org/SparkHub/gs-store-request-id.svg?branch=master)](https://travis-ci.org/SparkHub/gs-store-request-id)
3
+ [![Code Climate](https://codeclimate.com/github/SparkHub/gs-store-request-id/badges/gpa.svg)](https://codeclimate.com/github/SparkHub/gs-store-request-id)
4
+ [![Test Coverage](https://codeclimate.com/github/SparkHub/gs-store-request-id/badges/coverage.svg)](https://codeclimate.com/github/SparkHub/gs-store-request-id/coverage)
5
+ [![Issue Count](https://codeclimate.com/github/SparkHub/gs-store-request-id/badges/issue_count.svg)](https://codeclimate.com/github/SparkHub/gs-store-request-id)
6
+ [![Dependency Status](https://gemnasium.com/SparkHub/gs-store-request-id.svg)](https://gemnasium.com/SparkHub/gs-store-request-id)
7
+
8
+ # StoreRequestId
9
+
10
+ Middleware storing the unique [requestId](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/request_id.rb) into a [RequestStore](https://github.com/steveklabnik/request_store) in order to access it anytime.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'store_request_id', '~> 0.1.0'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install store_request_id
27
+
28
+ _**Using without rails:** If you're not using Rails, you need to insert `StoreRequestId::Middleware` into your middleware stack._
29
+
30
+ ## Usage
31
+
32
+ By default, `RequestStore` will be used as a data store. The `request_id` will be stored within a `:x_request_id` key. This value can be accessed wherever in the code with `StoreRequestId.request_id`.
33
+
34
+ If for some reason you want to personalize that key (collision for example), you can do so with:
35
+ ```ruby
36
+ # config/initializers/store_request_id.rb
37
+ StoreRequestId.configuration.request_store_key = :my_key
38
+ # OR
39
+ StoreRequestId.configure do |config|
40
+ config.request_store_key = :my_key
41
+ end
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Running CI tools
51
+
52
+ To run rubocop:
53
+
54
+ $ rubocop
55
+
56
+ To run reek:
57
+
58
+ $ reek
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SparkHub/gs-store-request-id. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'store_request_id'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StoreRequestId
4
+ class Configuration
5
+ # :reek:Attribute
6
+ attr_accessor :request_store_key
7
+
8
+ private
9
+
10
+ def initialize
11
+ self.request_store_key = store_key
12
+ end
13
+
14
+ def header_key
15
+ request_id_class = ::ActionDispatch::RequestId
16
+ defined?(request_id_class::X_REQUEST_ID) ? request_id_class::X_REQUEST_ID : 'X-Request-Id'
17
+ end
18
+
19
+ def store_key
20
+ header_key.downcase.tr('-', '_').to_sym
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StoreRequestId
4
+ class Middleware
5
+ def call(env)
6
+ req = ::ActionDispatch::Request.new(env)
7
+ StoreRequestId.request_id = req.uuid
8
+ @app.call(env)
9
+ end
10
+
11
+ private
12
+
13
+ def initialize(app)
14
+ @app = app
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'store_request_id/middleware'
4
+
5
+ module StoreRequestId
6
+ class Railtie < Rails::Railtie
7
+ initializer 'store_request_id.configure_rails_initialization' do
8
+ Rails.application.middleware.insert_after ActionDispatch::RequestId,
9
+ StoreRequestId::Middleware
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StoreRequestId
4
+ module RequestId
5
+ def request_id
6
+ RequestStore[configuration.request_store_key]
7
+ end
8
+
9
+ def request_id=(value)
10
+ RequestStore[configuration.request_store_key] = value
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'configuration'
4
+
5
+ module StoreRequestId
6
+ module Setup
7
+ def configuration
8
+ @configuration ||= self::Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield(configuration)
13
+ end
14
+
15
+ private
16
+
17
+ attr_writer :configuration
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StoreRequestId
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'store_request_id/version'
4
+ require 'store_request_id/setup'
5
+ require 'store_request_id/request_id'
6
+
7
+ module StoreRequestId
8
+ extend Setup
9
+ extend RequestId
10
+ end
11
+
12
+ require 'store_request_id/rails' if defined?(Rails::Railtie)
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'store_request_id/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'store_request_id'
9
+ spec.version = StoreRequestId::VERSION
10
+ spec.authors = ['Guidespark', 'Maxime Chaisse-Leal']
11
+ spec.email = ['sysadmin@guidespark.com', 'maxime.chaisseleal@gmail.com']
12
+
13
+ spec.summary = 'Store the unique request id within a global state (RequestStore).'
14
+ spec.description = 'Store the unique request id within a global state (RequestStore).'
15
+ spec.homepage = 'https://github.com/SparkHub/gs-store-request-id'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'actionpack', '>= 3.0.2'
26
+ spec.add_dependency 'activesupport', RUBY_VERSION >= '2.2.2' ? '>= 3.0.2' : '< 5.1.3'
27
+ spec.add_dependency 'request_store', '>= 1.1'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.14'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: store_request_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guidespark
8
+ - Maxime Chaisse-Leal
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-08-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 3.0.2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 3.0.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.0.2
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.0.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: request_store
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '1.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '1.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.14'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.14'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ description: Store the unique request id within a global state (RequestStore).
99
+ email:
100
+ - sysadmin@guidespark.com
101
+ - maxime.chaisseleal@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".codeclimate.yml"
107
+ - ".gitignore"
108
+ - ".reek"
109
+ - ".rspec"
110
+ - ".rubocop.yml"
111
+ - ".travis.yml"
112
+ - CHANGELOG.md
113
+ - CODE_OF_CONDUCT.md
114
+ - Gemfile
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - bin/console
119
+ - bin/setup
120
+ - lib/store_request_id.rb
121
+ - lib/store_request_id/configuration.rb
122
+ - lib/store_request_id/middleware.rb
123
+ - lib/store_request_id/rails.rb
124
+ - lib/store_request_id/request_id.rb
125
+ - lib/store_request_id/setup.rb
126
+ - lib/store_request_id/version.rb
127
+ - store_request_id.gemspec
128
+ homepage: https://github.com/SparkHub/gs-store-request-id
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.6.11
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Store the unique request id within a global state (RequestStore).
152
+ test_files: []