Class: Equipoise::Configuration
- Inherits:
-
Object
- Object
- Equipoise::Configuration
- Defined in:
- lib/equipoise/configuration.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://app.equipoi.se/api/v1"- DEFAULT_OPEN_TIMEOUT =
5- DEFAULT_READ_TIMEOUT =
30- DEFAULT_MAX_RETRIES =
2- DEFAULT_BATCH_SIZE =
500- READ_TIMEOUT_BOUNDS =
Hard limits — every producer-tunable transport knob is clamped into these ranges so a misconfigured producer can never punish the receiver:
read_timeout — floor keeps the producer patient enough that one slow batch doesn't become two concurrent deliveries (a low timeout is how a retry double-submits); ceiling stops a producer worker hanging forever. max_retries — ceiling means a misconfig can't retry-storm the receiver. batch_size — ceiling is the receiver's own per-batch cap (it rejects anything larger); floor of 1 keeps slicing sane.Out-of-range values are clamped, not raised (see #clamp_to).
(5..120).freeze
- MAX_RETRIES_BOUNDS =
(0..5).freeze
- BATCH_SIZE_BOUNDS =
(1..500).freeze
- LOOPBACK_HOSTS =
%w[localhost 127.0.0.1 ::1 [::1]].freeze
- PRODUCTION_HOST =
"app.equipoi.se"
URI.parse(DEFAULT_BASE_URL).host
Instance Attribute Summary collapse
-
#allow_insecure_http ⇒ Object
Returns the value of attribute allow_insecure_http.
-
#api_key ⇒ Object
Explicit assignment wins; otherwise read ENV each call (rotation-aware).
- #base_url ⇒ Object
-
#batch_size ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retries ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
-
#max_retry_backoff ⇒ Object
Returns the value of attribute max_retry_backoff.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
-
#retry_backoff_base ⇒ Object
Returns the value of attribute retry_backoff_base.
- #source ⇒ Object
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
-
#bounded_batch_size(requested = nil) ⇒ Object
The effective per-request chunk size: an explicit
batch_sync(chunk_size:)wins, else the configured batch_size — but either way clamped to the receiver's hard cap so the gem never posts an oversized (and rejected) batch. -
#disabled? ⇒ Boolean
Test-mode kill switch.
-
#initialize(env: ENV) ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize(env: ENV) ⇒ Configuration
Returns a new instance of Configuration.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/equipoise/configuration.rb', line 70 def initialize(env: ENV) @env = env @api_key = nil @base_url = nil @source = nil @open_timeout = DEFAULT_OPEN_TIMEOUT @read_timeout = DEFAULT_READ_TIMEOUT @max_retries = DEFAULT_MAX_RETRIES @batch_size = DEFAULT_BATCH_SIZE @retry_backoff_base = 0.5 @max_retry_backoff = 30 @allow_insecure_http = false @enabled = true @logger = nil @user_agent = "equipoise-ruby/#{Equipoise::VERSION}" end |
Instance Attribute Details
#allow_insecure_http ⇒ Object
Returns the value of attribute allow_insecure_http.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def allow_insecure_http @allow_insecure_http end |
#api_key ⇒ Object
Explicit assignment wins; otherwise read ENV each call (rotation-aware).
96 97 98 |
# File 'lib/equipoise/configuration.rb', line 96 def api_key resolve(@api_key, "EQUIPOISE_API_KEY") end |
#base_url ⇒ Object
100 101 102 |
# File 'lib/equipoise/configuration.rb', line 100 def base_url resolve(@base_url, "EQUIPOISE_API_URL") || DEFAULT_BASE_URL end |
#batch_size ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
63 64 65 |
# File 'lib/equipoise/configuration.rb', line 63 def batch_size @batch_size end |
#enabled ⇒ Object
Returns the value of attribute enabled.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def enabled @enabled end |
#logger ⇒ Object
Returns the value of attribute logger.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def logger @logger end |
#max_retries ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
63 64 65 |
# File 'lib/equipoise/configuration.rb', line 63 def max_retries @max_retries end |
#max_retry_backoff ⇒ Object
Returns the value of attribute max_retry_backoff.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def max_retry_backoff @max_retry_backoff end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Clamped knobs — custom writers (below) hold every override inside its *_BOUNDS so the gem stays a good citizen no matter what a producer sets.
63 64 65 |
# File 'lib/equipoise/configuration.rb', line 63 def read_timeout @read_timeout end |
#retry_backoff_base ⇒ Object
Returns the value of attribute retry_backoff_base.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def retry_backoff_base @retry_backoff_base end |
#source ⇒ Object
104 105 106 |
# File 'lib/equipoise/configuration.rb', line 104 def source resolve(@source, "EQUIPOISE_SOURCE") end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
54 55 56 |
# File 'lib/equipoise/configuration.rb', line 54 def user_agent @user_agent end |
Instance Method Details
#bounded_batch_size(requested = nil) ⇒ Object
The effective per-request chunk size: an explicit
batch_sync(chunk_size:) wins, else the configured batch_size — but either
way clamped to the receiver's hard cap so the gem never posts an oversized
(and rejected) batch.
130 131 132 |
# File 'lib/equipoise/configuration.rb', line 130 def bounded_batch_size(requested = nil) clamp_to(:batch_size, (requested || batch_size).to_i, BATCH_SIZE_BOUNDS) end |
#disabled? ⇒ Boolean
Test-mode kill switch. When disabled the client short-circuits to a no-op before any network call OR validation, so a stray EQUIPOISE_API_KEY in a producer's test env can never make a live call.
90 91 92 |
# File 'lib/equipoise/configuration.rb', line 90 def disabled? !enabled end |
#validate! ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/equipoise/configuration.rb', line 134 def validate! raise ConfigurationError, "api_key is required (set EQUIPOISE_API_KEY or Equipoise.configure)" if api_key.to_s.empty? raise ConfigurationError, "base_url is required" if base_url.to_s.empty? ensure_secure_transport! ensure_environment_match! true end |