Sha256: ef895afea4e29f74e394d6515914555dd17fb26b711caa806854c1f0d9bc08c3

Contents?: true

Size: 804 Bytes

Versions: 4

Compression:

Stored size: 804 Bytes

Contents

module RailsSettings
  if defined? ActiveSupport::CurrentAttributes 
    # For storage all settings in Current, it will reset after per request completed.
    # Base on ActiveSupport::CurrentAttributes
    # https://api.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html
    class RequestCache < ActiveSupport::CurrentAttributes 
      attribute :settings
    end
  else
    # https://github.com/steveklabnik/request_store
    # For Rails 5.0
    require "request_store"

    class RequestCache
      class << self
        def reset
          self.settings = nil
        end

        def settings
          RequestStore.store[:rails_settings_all_settings]
        end

        def settings=(val)
          RequestStore.store[:rails_settings_all_settings]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails-settings-cached-2.5.2 lib/rails-settings/request_cache.rb
rails-settings-cached-2.5.1 lib/rails-settings/request_cache.rb
rails-settings-cached-2.5.0 lib/rails-settings/request_cache.rb
rails-settings-cached-2.4.1 lib/rails-settings/request_cache.rb