Class: DedupeRequests::Configuration
- Inherits:
-
Object
- Object
- DedupeRequests::Configuration
- Defined in:
- lib/dedupe_requests/configuration.rb
Constant Summary collapse
- MODES =
%i[off observe enforce].freeze
- DEFAULT_CONFLICT_BODY =
{ "errors" => [{ "error_key" => "base", "category" => "duplicate_operation", "message" => "Duplicate request detected. A matching request is in-flight or recently completed." }] }.freeze
- DEFAULT_CALLER_ID =
Per-caller identity. The callable is given the CONTROLLER, so it can read anything the controller exposes — ‘current_user`, a helper method, or a header via `controller.request`. Examples:
c.caller_id = ->(controller) { controller.current_user&.id } c.caller_id = ->(controller) { controller.request.get_header("HTTP_X_API_KEY") }The default derives identity from the request’s Authorization header, falling back to a Rails-style session cookie (so token- and cookie-auth apps work with no configuration). It accepts either a controller or a bare request.
lambda do |context| request = context.respond_to?(:request) ? context.request : context if request.respond_to?(:get_header) auth = request.get_header("HTTP_AUTHORIZATION") return auth if auth && !auth.to_s.empty? end if request.respond_to?(:cookies) request..each { |name, value| return value if name.to_s =~ /\A_.*_session\z/i } end nil end
Instance Attribute Summary collapse
-
#caller_id ⇒ Object
Returns the value of attribute caller_id.
- #conflict_body ⇒ Object
-
#conflict_status ⇒ Object
Returns the value of attribute conflict_status.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#on_duplicate_detected ⇒ Object
Returns the value of attribute on_duplicate_detected.
-
#on_duplicate_rejected ⇒ Object
Returns the value of attribute on_duplicate_rejected.
-
#redis ⇒ Object
Returns the value of attribute redis.
- #store ⇒ Object
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dedupe_requests/configuration.rb', line 43 def initialize @redis = nil @store = nil @mode = :enforce @ttl = 90 @digest = :sha256 @namespace = "dedupe_requests" @caller_id = DEFAULT_CALLER_ID @fingerprint = nil @conflict_status = 409 @logger = nil @on_duplicate_detected = nil @on_duplicate_rejected = nil @conflict_body = nil end |
Instance Attribute Details
#caller_id ⇒ Object
Returns the value of attribute caller_id.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def caller_id @caller_id end |
#conflict_body ⇒ Object
76 77 78 |
# File 'lib/dedupe_requests/configuration.rb', line 76 def conflict_body @conflict_body || DEFAULT_CONFLICT_BODY end |
#conflict_status ⇒ Object
Returns the value of attribute conflict_status.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def conflict_status @conflict_status end |
#digest ⇒ Object
Returns the value of attribute digest.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def digest @digest end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def fingerprint @fingerprint end |
#logger ⇒ Object
Returns the value of attribute logger.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def logger @logger end |
#mode ⇒ Object
Returns the value of attribute mode.
41 42 43 |
# File 'lib/dedupe_requests/configuration.rb', line 41 def mode @mode end |
#namespace ⇒ Object
Returns the value of attribute namespace.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def namespace @namespace end |
#on_duplicate_detected ⇒ Object
Returns the value of attribute on_duplicate_detected.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def on_duplicate_detected @on_duplicate_detected end |
#on_duplicate_rejected ⇒ Object
Returns the value of attribute on_duplicate_rejected.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def on_duplicate_rejected @on_duplicate_rejected end |
#redis ⇒ Object
Returns the value of attribute redis.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def redis @redis end |
#store ⇒ Object
72 73 74 |
# File 'lib/dedupe_requests/configuration.rb', line 72 def store @store ||= (RedisStore.new(@redis, namespace: @namespace, logger: @logger) if @redis) end |
#ttl ⇒ Object
Returns the value of attribute ttl.
37 38 39 |
# File 'lib/dedupe_requests/configuration.rb', line 37 def ttl @ttl end |
Instance Method Details
#enabled? ⇒ Boolean
68 69 70 |
# File 'lib/dedupe_requests/configuration.rb', line 68 def enabled? @mode != :off end |