store_request_id 0.1.0 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +10 -1
- data/Gemfile +1 -0
- data/README.md +27 -6
- data/lib/store_request_id/configuration.rb +14 -11
- data/lib/store_request_id/defaults/storage.rb +23 -0
- data/lib/store_request_id/request_id.rb +12 -2
- data/lib/store_request_id/store.rb +12 -0
- data/lib/store_request_id/version.rb +1 -1
- data/lib/store_request_id.rb +1 -0
- data/store_request_id.gemspec +2 -3
- metadata +6 -18
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f80dbf0c478751acf453336292f7386c18da2834
         | 
| 4 | 
            +
              data.tar.gz: '088b0d5427e897848c1c3a2186059fd4f6af6135'
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 709a4e192b30035d64d51682410962eea2e38a4d5fc182f8cad91684b54f2c92722746b44fa6c5ee1d928599001b4e39c1c735886e0f99c8456dc9f5251e1516
         | 
| 7 | 
            +
              data.tar.gz: 63fca3c31a7aed76ce5ca68397f38b8c735f6e7921c397a5a05f85b7c0a481d4a11fdc0c982f810cd47909d4461b9ed57c5f2d60b63f88755988c41f493c41a9
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,4 +1,13 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            # Change Log
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ## [0.2.0](https://github.com/SparkHub/gs-store-request-id/tree/v0.2.0) (2017-08-14)
         | 
| 4 | 
            +
            [Full Changelog](https://github.com/SparkHub/gs-store-request-id/compare/v0.1.0...v0.2.0)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            **Implemented enhancements:**
         | 
| 7 | 
            +
            - Data storage is now configurable ([mchaisse](https://github.com/mchaisse))
         | 
| 8 | 
            +
            - Remove `RequestStore` dependency ([mchaisse](https://github.com/mchaisse))
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ## [0.1.0](https://github.com/SparkHub/gs-store-request-id/tree/v0.1.0) (2017-08-11)
         | 
| 2 11 |  | 
| 3 12 | 
             
            **Implemented enhancements:**
         | 
| 4 13 | 
             
            - Initial version :tada: ([mchaisse](https://github.com/mchaisse))
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            [](http://badge.fury.io/rb/store_request_id)
         | 
| 2 2 | 
             
            [](https://travis-ci.org/SparkHub/gs-store-request-id)
         | 
| 3 3 | 
             
            [](https://codeclimate.com/github/SparkHub/gs-store-request-id)
         | 
| 4 4 | 
             
            [](https://codeclimate.com/github/SparkHub/gs-store-request-id/coverage)
         | 
| @@ -7,14 +7,14 @@ | |
| 7 7 |  | 
| 8 8 | 
             
            # StoreRequestId
         | 
| 9 9 |  | 
| 10 | 
            -
            Middleware storing the unique [requestId](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/request_id.rb) into a  | 
| 10 | 
            +
            Middleware storing the unique [requestId](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/request_id.rb) into a global value in order to access it anytime.
         | 
| 11 11 |  | 
| 12 12 | 
             
            ## Installation
         | 
| 13 13 |  | 
| 14 14 | 
             
            Add this line to your application's Gemfile:
         | 
| 15 15 |  | 
| 16 16 | 
             
            ```ruby
         | 
| 17 | 
            -
            gem 'store_request_id', '~> 0. | 
| 17 | 
            +
            gem 'store_request_id', '~> 0.2.0'
         | 
| 18 18 | 
             
            ```
         | 
| 19 19 |  | 
| 20 20 | 
             
            And then execute:
         | 
| @@ -29,15 +29,36 @@ _**Using without rails:** If you're not using Rails, you need to insert `StoreRe | |
| 29 29 |  | 
| 30 30 | 
             
            ## Usage
         | 
| 31 31 |  | 
| 32 | 
            -
            By default, ` | 
| 32 | 
            +
            By default, `Thread.current` 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 | 
            +
            ## Configuration
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            - **Storage object**
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            The storage can be changed. Storage objects must have `[]` and `[]=` methods. A proc should be sent to the configuration.
         | 
| 39 | 
            +
            Here is an example with the [RequestStore gem](https://github.com/steveklabnik/request_store).
         | 
| 40 | 
            +
            ```ruby
         | 
| 41 | 
            +
            # RequestStore needs to be installed prior
         | 
| 42 | 
            +
            # Gemfile
         | 
| 43 | 
            +
            gem 'request_store', '~> 1.1'
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            # config/initializers/store_request_id.rb
         | 
| 46 | 
            +
            StoreRequestId.configuration.storage = proc { RequestStore }
         | 
| 47 | 
            +
            # OR
         | 
| 48 | 
            +
            StoreRequestId.configure do |config|
         | 
| 49 | 
            +
              config.storage = proc { RequestStore }
         | 
| 50 | 
            +
            end
         | 
| 51 | 
            +
            ```
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            - **Storage key**
         | 
| 33 54 |  | 
| 34 55 | 
             
            If for some reason you want to personalize that key (collision for example), you can do so with:
         | 
| 35 56 | 
             
            ```ruby
         | 
| 36 57 | 
             
            # config/initializers/store_request_id.rb
         | 
| 37 | 
            -
            StoreRequestId.configuration. | 
| 58 | 
            +
            StoreRequestId.configuration.storage_key = :my_key
         | 
| 38 59 | 
             
            # OR
         | 
| 39 60 | 
             
            StoreRequestId.configure do |config|
         | 
| 40 | 
            -
              config. | 
| 61 | 
            +
              config.storage_key = :my_key
         | 
| 41 62 | 
             
            end
         | 
| 42 63 | 
             
            ```
         | 
| 43 64 |  | 
| @@ -1,23 +1,26 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            +
            require_relative 'defaults/storage'
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
            module StoreRequestId
         | 
| 6 | 
            +
              # :reek:Attribute
         | 
| 7 | 
            +
              # :reek:InstanceVariableAssumption
         | 
| 4 8 | 
             
              class Configuration
         | 
| 5 | 
            -
                 | 
| 6 | 
            -
                attr_accessor :request_store_key
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                private
         | 
| 9 | 
            +
                attr_accessor :storage_key
         | 
| 9 10 |  | 
| 10 | 
            -
                def  | 
| 11 | 
            -
                   | 
| 11 | 
            +
                def storage
         | 
| 12 | 
            +
                  @storage.caller
         | 
| 12 13 | 
             
                end
         | 
| 13 14 |  | 
| 14 | 
            -
                def  | 
| 15 | 
            -
                   | 
| 16 | 
            -
                  defined?(request_id_class::X_REQUEST_ID) ? request_id_class::X_REQUEST_ID : 'X-Request-Id'
         | 
| 15 | 
            +
                def storage=(store)
         | 
| 16 | 
            +
                  @storage = Store.new(store)
         | 
| 17 17 | 
             
                end
         | 
| 18 18 |  | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 19 | 
            +
                private
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def initialize
         | 
| 22 | 
            +
                  self.storage_key = Defaults::Storage.generate_key
         | 
| 23 | 
            +
                  self.storage     = proc { Thread.current }
         | 
| 21 24 | 
             
                end
         | 
| 22 25 | 
             
              end
         | 
| 23 26 | 
             
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module StoreRequestId
         | 
| 4 | 
            +
              module Defaults
         | 
| 5 | 
            +
                module Storage
         | 
| 6 | 
            +
                  DEFAULT_KEY = 'X-Request-Id'.freeze
         | 
| 7 | 
            +
                  private_constant :DEFAULT_KEY
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  class << self
         | 
| 10 | 
            +
                    def generate_key
         | 
| 11 | 
            +
                      header_key.downcase.tr('-', '_').to_sym
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                    private
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    def header_key
         | 
| 17 | 
            +
                      request_id_class = ::ActionDispatch::RequestId
         | 
| 18 | 
            +
                      defined?(request_id_class::X_REQUEST_ID) ? request_id_class::X_REQUEST_ID : DEFAULT_KEY
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -3,11 +3,21 @@ | |
| 3 3 | 
             
            module StoreRequestId
         | 
| 4 4 | 
             
              module RequestId
         | 
| 5 5 | 
             
                def request_id
         | 
| 6 | 
            -
                   | 
| 6 | 
            +
                  storage[storage_key]
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 9 | 
             
                def request_id=(value)
         | 
| 10 | 
            -
                   | 
| 10 | 
            +
                  storage[storage_key] = value
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                private
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def storage
         | 
| 16 | 
            +
                  configuration.storage
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def storage_key
         | 
| 20 | 
            +
                  configuration.storage_key
         | 
| 11 21 | 
             
                end
         | 
| 12 22 | 
             
              end
         | 
| 13 23 | 
             
            end
         | 
    
        data/lib/store_request_id.rb
    CHANGED
    
    
    
        data/store_request_id.gemspec
    CHANGED
    
    | @@ -10,8 +10,8 @@ Gem::Specification.new do |spec| | |
| 10 10 | 
             
              spec.authors       = ['Guidespark', 'Maxime Chaisse-Leal']
         | 
| 11 11 | 
             
              spec.email         = ['sysadmin@guidespark.com', 'maxime.chaisseleal@gmail.com']
         | 
| 12 12 |  | 
| 13 | 
            -
              spec.summary       = 'Store the unique request id within a global state | 
| 14 | 
            -
              spec.description   = 'Store the unique request id within a global state | 
| 13 | 
            +
              spec.summary       = 'Store the unique request id within a global state.'
         | 
| 14 | 
            +
              spec.description   = 'Store the unique request id within a global state.'
         | 
| 15 15 | 
             
              spec.homepage      = 'https://github.com/SparkHub/gs-store-request-id'
         | 
| 16 16 | 
             
              spec.license       = 'MIT'
         | 
| 17 17 |  | 
| @@ -24,7 +24,6 @@ Gem::Specification.new do |spec| | |
| 24 24 |  | 
| 25 25 | 
             
              spec.add_dependency 'actionpack', '>= 3.0.2'
         | 
| 26 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 27 |  | 
| 29 28 | 
             
              spec.add_development_dependency 'bundler', '~> 1.14'
         | 
| 30 29 | 
             
              spec.add_development_dependency 'rake', '~> 10.0'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: store_request_id
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Guidespark
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2017-08- | 
| 12 | 
            +
            date: 2017-08-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: actionpack
         | 
| @@ -39,20 +39,6 @@ dependencies: | |
| 39 39 | 
             
                - - ">="
         | 
| 40 40 | 
             
                  - !ruby/object:Gem::Version
         | 
| 41 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 42 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 57 43 | 
             
              name: bundler
         | 
| 58 44 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -95,7 +81,7 @@ dependencies: | |
| 95 81 | 
             
                - - "~>"
         | 
| 96 82 | 
             
                  - !ruby/object:Gem::Version
         | 
| 97 83 | 
             
                    version: '3.0'
         | 
| 98 | 
            -
            description: Store the unique request id within a global state | 
| 84 | 
            +
            description: Store the unique request id within a global state.
         | 
| 99 85 | 
             
            email:
         | 
| 100 86 | 
             
            - sysadmin@guidespark.com
         | 
| 101 87 | 
             
            - maxime.chaisseleal@gmail.com
         | 
| @@ -119,10 +105,12 @@ files: | |
| 119 105 | 
             
            - bin/setup
         | 
| 120 106 | 
             
            - lib/store_request_id.rb
         | 
| 121 107 | 
             
            - lib/store_request_id/configuration.rb
         | 
| 108 | 
            +
            - lib/store_request_id/defaults/storage.rb
         | 
| 122 109 | 
             
            - lib/store_request_id/middleware.rb
         | 
| 123 110 | 
             
            - lib/store_request_id/rails.rb
         | 
| 124 111 | 
             
            - lib/store_request_id/request_id.rb
         | 
| 125 112 | 
             
            - lib/store_request_id/setup.rb
         | 
| 113 | 
            +
            - lib/store_request_id/store.rb
         | 
| 126 114 | 
             
            - lib/store_request_id/version.rb
         | 
| 127 115 | 
             
            - store_request_id.gemspec
         | 
| 128 116 | 
             
            homepage: https://github.com/SparkHub/gs-store-request-id
         | 
| @@ -148,5 +136,5 @@ rubyforge_project: | |
| 148 136 | 
             
            rubygems_version: 2.6.11
         | 
| 149 137 | 
             
            signing_key: 
         | 
| 150 138 | 
             
            specification_version: 4
         | 
| 151 | 
            -
            summary: Store the unique request id within a global state | 
| 139 | 
            +
            summary: Store the unique request id within a global state.
         | 
| 152 140 | 
             
            test_files: []
         |