Module: Familia::Settings
- Included in:
- Familia, DataType, Horreum::DefinitionMethods
- Defined in:
- lib/familia/settings.rb
Overview
Familia::Settings
Instance Attribute Summary collapse
- #current_key_version(val = nil) ⇒ Object
- #default_expiration(v = nil) ⇒ Object
- #delim(val = nil) ⇒ Object
- #encryption_keys(val = nil) ⇒ Object
-
#encryption_personalization(val = nil) ⇒ String
Personalization string for BLAKE2b key derivation in XChaCha20Poly1305.
- #logical_database(v = nil) ⇒ Object
- #prefix(val = nil) ⇒ Object
-
#raise_on_unsaved_parent_write(val = nil) ⇒ Boolean
Controls whether a collection write on a DataType raises when the parent Horreum is a new, unsaved object — one whose hash key does not exist in the database yet.
-
#schema_path(val = nil) ⇒ String, ...
Directory containing schema files for JSON Schema validation.
-
#schema_validator(val = nil) ⇒ Symbol, Object
Validator type for JSON Schema validation.
-
#schemas(val = nil) ⇒ Hash
Hash mapping class names to their schema file paths.
-
#strict_write_order(val = nil) ⇒ Boolean
Controls whether collection writes on a DataType raise an error when the parent Horreum object has unsaved scalar field changes.
- #suffix(val = nil) ⇒ Object
-
#transaction_mode(val = nil) ⇒ Symbol
Controls transaction behavior when connection handlers don't support transactions.
Instance Method Summary collapse
-
#configure {|Settings| ... } ⇒ Settings
(also: #config)
Configure Familia settings.
-
#default_suffix ⇒ Object
We define this do-nothing method because it reads better than simply Familia.suffix in some contexts.
-
#dirty_write_warnings(val = nil) ⇒ Symbol
Global default for how collection writes react when the parent Horreum has unsaved scalar field changes.
- #dirty_write_warnings=(val) ⇒ Object
-
#pipelined_mode(val = nil) ⇒ Symbol
Controls pipeline behavior when connection handlers don't support pipelines.
- #pipelined_mode=(val) ⇒ Object
Instance Attribute Details
#current_key_version(val = nil) ⇒ Object
71 72 73 74 |
# File 'lib/familia/settings.rb', line 71 def current_key_version(val = nil) @current_key_version = val if val @current_key_version end |
#default_expiration(v = nil) ⇒ Object
49 50 51 52 |
# File 'lib/familia/settings.rb', line 49 def default_expiration(v = nil) @default_expiration = v unless v.nil? @default_expiration end |
#delim(val = nil) ⇒ Object
34 35 36 37 |
# File 'lib/familia/settings.rb', line 34 def delim(val = nil) @delim = val if val @delim end |
#encryption_keys(val = nil) ⇒ Object
66 67 68 69 |
# File 'lib/familia/settings.rb', line 66 def encryption_keys(val = nil) @encryption_keys = val if val @encryption_keys end |
#encryption_personalization(val = nil) ⇒ String
Personalization string for BLAKE2b key derivation in XChaCha20Poly1305. This provides cryptographic domain separation, ensuring derived keys are unique per application even with identical master keys and contexts. Must be 16 bytes or less (automatically padded with null bytes).
end
87 88 89 90 91 92 93 94 |
# File 'lib/familia/settings.rb', line 87 def encryption_personalization(val = nil) if val raise ArgumentError, 'Personalization string cannot exceed 16 bytes' if val.bytesize > 16 @encryption_personalization = val end @encryption_personalization end |
#logical_database(v = nil) ⇒ Object
54 55 56 57 58 |
# File 'lib/familia/settings.rb', line 54 def logical_database(v = nil) Familia.trace :DB, nil, "#{@logical_database} #{v}" if Familia.debug? @logical_database = v unless v.nil? @logical_database end |
#prefix(val = nil) ⇒ Object
39 40 41 42 |
# File 'lib/familia/settings.rb', line 39 def prefix(val = nil) @prefix = val if val @prefix end |
#raise_on_unsaved_parent_write(val = nil) ⇒ Boolean
Controls whether a collection write on a DataType raises when the parent Horreum is a new, unsaved object — one whose hash key does not exist in the database yet. This is the most dangerous dirty-write scenario: the collection lands in Redis while none of the parent's scalar data exists, orphaning the collection if the parent is never saved.
Defaults to true (raise) independently of #strict_write_order, because an orphaned-record bug is rarely what the caller intends. Set to false to downgrade to a (still distinct, still strong) warning emitted via Familia.warn instead.
Note: #strict_write_order, when true, raises for every dirty write and therefore still raises the new-object case even if this is set to false.
194 195 196 197 198 199 200 201 |
# File 'lib/familia/settings.rb', line 194 def raise_on_unsaved_parent_write(val = nil) @raise_on_unsaved_parent_write = val unless val.nil? # Defaults to true: an unset (nil) value means "raise". Cannot use # `|| true` here -- that would coerce an explicit `false` back to true. return true if @raise_on_unsaved_parent_write.nil? @raise_on_unsaved_parent_write end |
#schema_path(val = nil) ⇒ String, ...
Directory containing schema files for JSON Schema validation. When set, schema files are discovered by convention using the underscored class name (e.g., Customer -> customer.json).
259 260 261 262 |
# File 'lib/familia/settings.rb', line 259 def schema_path(val = nil) @schema_path = val if val @schema_path end |
#schema_validator(val = nil) ⇒ Symbol, Object
Validator type for JSON Schema validation.
Available options:
- :json_schemer (default): Use the json_schemer gem for validation
- :none: Disable schema validation entirely
- Custom instance: Any object responding to #validate
298 299 300 301 |
# File 'lib/familia/settings.rb', line 298 def schema_validator(val = nil) @schema_validator = val if val @schema_validator || :json_schemer end |
#schemas(val = nil) ⇒ Hash
Hash mapping class names to their schema file paths. Takes precedence over convention-based discovery via schema_path.
278 279 280 281 |
# File 'lib/familia/settings.rb', line 278 def schemas(val = nil) @schemas = val if val @schemas || {} end |
#strict_write_order(val = nil) ⇒ Boolean
Controls whether collection writes on a DataType raise an error when the parent Horreum object has unsaved scalar field changes.
When false (default), a warning is emitted via Familia.warn. When true, a Familia::Problem exception is raised.
167 168 169 170 |
# File 'lib/familia/settings.rb', line 167 def strict_write_order(val = nil) @strict_write_order = val unless val.nil? @strict_write_order || false end |
#suffix(val = nil) ⇒ Object
44 45 46 47 |
# File 'lib/familia/settings.rb', line 44 def suffix(val = nil) @suffix = val if val @suffix end |
#transaction_mode(val = nil) ⇒ Symbol
Controls transaction behavior when connection handlers don't support transactions
Available modes:
- :warn (default): Log warning and execute commands individually
- :strict: Raise OperationModeError when transaction unavailable
- :permissive: Silently execute commands individually
111 112 113 114 115 116 117 118 119 |
# File 'lib/familia/settings.rb', line 111 def transaction_mode(val = nil) if val unless [:strict, :warn, :permissive].include?(val) raise ArgumentError, 'Transaction mode must be :strict, :warn, or :permissive' end @transaction_mode = val end @transaction_mode || :warn # default to warn mode end |
Instance Method Details
#configure {|Settings| ... } ⇒ Settings Also known as: config
Configure Familia settings
316 317 318 319 |
# File 'lib/familia/settings.rb', line 316 def configure yield self if block_given? self end |
#default_suffix ⇒ Object
We define this do-nothing method because it reads better than simply Familia.suffix in some contexts.
62 63 64 |
# File 'lib/familia/settings.rb', line 62 def default_suffix suffix end |
#dirty_write_warnings(val = nil) ⇒ Symbol
Global default for how collection writes react when the parent Horreum has unsaved scalar field changes. Acts as the fallback when a Horreum subclass does not set its own +dirty_write_warnings+ class setting.
The resolved mode drives both warning and raise behavior: :warn/:once control warning frequency, :strict forces a raise, and :off suppresses everything (warnings and raises) for the class. See the precedence note below and Familia::DataType#warn_if_dirty!.
Available modes:
- :once (default): Warn once per distinct dirty-field signature within a dirty window (deduped). A change to the dirty set warns again.
- :warn: Warn on every collection write (legacy behavior).
- :strict: Raise Familia::Problem on every violation.
- :off: Suppress warnings entirely.
Note: +Familia.strict_write_order = true+ raises for any class whose mode is not explicitly +:off+. A class-level +:off+ is authoritative -- it suppresses both warnings and raises, overriding +strict_write_order+ and +raise_on_unsaved_parent_write+. "Off means off."
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/familia/settings.rb', line 232 def dirty_write_warnings(val = nil) unless val.nil? valid = %i[strict warn once off] unless valid.include?(val) raise ArgumentError, "dirty_write_warnings must be one of #{valid.inspect}, got #{val.inspect}" end @dirty_write_warnings = val end @dirty_write_warnings || :once end |
#dirty_write_warnings=(val) ⇒ Object
243 244 245 |
# File 'lib/familia/settings.rb', line 243 def dirty_write_warnings=(val) dirty_write_warnings(val) end |
#pipelined_mode(val = nil) ⇒ Symbol
Controls pipeline behavior when connection handlers don't support pipelines
Available modes:
- :warn (default): Log warning and execute commands individually
- :strict: Raise OperationModeError when pipeline unavailable
- :permissive: Silently execute commands individually
136 137 138 139 140 141 142 143 144 |
# File 'lib/familia/settings.rb', line 136 def pipelined_mode(val = nil) if val unless [:strict, :warn, :permissive].include?(val) raise ArgumentError, 'Pipeline mode must be :strict, :warn, or :permissive' end @pipelined_mode = val end @pipelined_mode || :warn # default to warn mode end |
#pipelined_mode=(val) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/familia/settings.rb', line 146 def pipelined_mode=(val) unless [:strict, :warn, :permissive].include?(val) raise ArgumentError, 'Pipeline mode must be :strict, :warn, or :permissive' end @pipelined_mode = val end |