Class: PgAnyWhere::Configuration
- Inherits:
-
Object
- Object
- PgAnyWhere::Configuration
- Defined in:
- lib/pg_any_where/configuration.rb
Overview
Configuration for the PgAnyWhere gem.
Set options via the block form:
PgAnyWhere.configure do |config|
config.enabled = true
config.min_array_size = 2
end
Or via environment variables (ENV values act as defaults when the attribute has not been explicitly set):
PG_ANY_WHERE_ENABLED = "true" | "false" (default: "true")
PG_ANY_WHERE_MIN_ARRAY_SIZE = integer (default: "0")
Instance Attribute Summary collapse
- #enabled ⇒ Boolean? writeonly
-
#min_array_size ⇒ Integer
Minimum array size required before the ANY / ALL rewrite is applied.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Whether the extension is active.
-
#reset! ⇒ Object
Reset all settings back to defaults (reads ENV again).
-
#use_for_values?(values) ⇒ Boolean
Returns true when the rewrite should be applied to
values.
Instance Attribute Details
#enabled=(value) ⇒ Boolean? (writeonly)
21 22 23 |
# File 'lib/pg_any_where/configuration.rb', line 21 def enabled=(value) @enabled = value end |
#min_array_size ⇒ Integer
Minimum array size required before the ANY / ALL rewrite is applied. Arrays smaller than this threshold fall back to the standard IN / NOT IN.
43 44 45 |
# File 'lib/pg_any_where/configuration.rb', line 43 def min_array_size @min_array_size || ENV.fetch("PG_ANY_WHERE_MIN_ARRAY_SIZE", "0").to_i end |
Instance Method Details
#enabled? ⇒ Boolean
Whether the extension is active.
Explicit Ruby config takes precedence over the environment variable.
31 32 33 34 35 36 37 |
# File 'lib/pg_any_where/configuration.rb', line 31 def enabled? if @enabled.nil? ENV.fetch("PG_ANY_WHERE_ENABLED", "true") == "true" else @enabled end end |
#reset! ⇒ Object
Reset all settings back to defaults (reads ENV again).
58 59 60 61 62 |
# File 'lib/pg_any_where/configuration.rb', line 58 def reset! @enabled = nil @min_array_size = nil self end |
#use_for_values?(values) ⇒ Boolean
Returns true when the rewrite should be applied to values.
51 52 53 54 55 |
# File 'lib/pg_any_where/configuration.rb', line 51 def use_for_values?(values) enabled? && values.is_a?(Array) && values.size >= min_array_size end |