Module: Familia::Settings

Included in:
Familia, DataType, Horreum::DefinitionMethods
Defined in:
lib/familia/settings.rb

Overview

Familia::Settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_key_version(val = nil) ⇒ Object



67
68
69
70
# File 'lib/familia/settings.rb', line 67

def current_key_version(val = nil)
  @current_key_version = val if val
  @current_key_version
end

#default_expiration(v = nil) ⇒ Object



45
46
47
48
# File 'lib/familia/settings.rb', line 45

def default_expiration(v = nil)
  @default_expiration = v unless v.nil?
  @default_expiration
end

#delim(val = nil) ⇒ Object



30
31
32
33
# File 'lib/familia/settings.rb', line 30

def delim(val = nil)
  @delim = val if val
  @delim
end

#encryption_keys(val = nil) ⇒ Object



62
63
64
65
# File 'lib/familia/settings.rb', line 62

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

Examples:

Familia.configure do |config|

config.encryption_personalization = 'MyApp1.0'

Parameters:

  • val (String, nil) (defaults to: nil)

    The personalization string, or nil to get current value

Returns:

  • (String)

    Current personalization string



83
84
85
86
87
88
89
90
# File 'lib/familia/settings.rb', line 83

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



50
51
52
53
54
# File 'lib/familia/settings.rb', line 50

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



35
36
37
38
# File 'lib/familia/settings.rb', line 35

def prefix(val = nil)
  @prefix = val if val
  @prefix
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).

Examples:

Convention-based schema discovery

Familia.configure do |config|
  config.schema_path = 'schemas/models'
end

Parameters:

  • val (String, Pathname, nil) (defaults to: nil)

    The schema directory path, or nil to get current value

Returns:

  • (String, Pathname, nil)

    Current schema path



161
162
163
164
# File 'lib/familia/settings.rb', line 161

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

Examples:

Disable validation

Familia.configure do |config|
  config.schema_validator = :none
end

Parameters:

  • val (Symbol, Object, nil) (defaults to: nil)

    The validator type or instance, or nil to get current

Returns:

  • (Symbol, Object)

    Current validator setting



200
201
202
203
# File 'lib/familia/settings.rb', line 200

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.

Examples:

Explicit schema mapping

Familia.configure do |config|
  config.schemas = {
    'Customer' => 'schemas/customer.json',
    'Session'  => 'schemas/session.json'
  }
end

Parameters:

  • val (Hash, nil) (defaults to: nil)

    A hash of class name => schema path mappings, or nil to get current

Returns:

  • (Hash)

    Current schema mappings



180
181
182
183
# File 'lib/familia/settings.rb', line 180

def schemas(val = nil)
  @schemas = val if val
  @schemas || {}
end

#suffix(val = nil) ⇒ Object



40
41
42
43
# File 'lib/familia/settings.rb', line 40

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

Examples:

Setting transaction mode

Familia.configure do |config|
  config.transaction_mode = :warn
end

Parameters:

  • val (Symbol, nil) (defaults to: nil)

    The transaction mode or nil to get current value

Returns:

  • (Symbol)

    Current transaction mode (:strict, :warn, :permissive)



107
108
109
110
111
112
113
114
115
# File 'lib/familia/settings.rb', line 107

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

Examples:

Block-based configuration

Familia.configure do |config|
  config.redis_uri = "redis://localhost:6379/1"
  config.ttl = 3600
end

Method chaining

Familia.configure.redis_uri = "redis://localhost:6379/1"

Yields:

  • (Settings)

    self for block-based configuration

Returns:

  • (Settings)

    self for method chaining



218
219
220
221
# File 'lib/familia/settings.rb', line 218

def configure
  yield self if block_given?
  self
end

#default_suffixObject

We define this do-nothing method because it reads better than simply Familia.suffix in some contexts.



58
59
60
# File 'lib/familia/settings.rb', line 58

def default_suffix
  suffix
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

Examples:

Setting pipeline mode

Familia.configure do |config|
  config.pipelined_mode = :permissive
end

Parameters:

  • val (Symbol, nil) (defaults to: nil)

    The pipeline mode or nil to get current value

Returns:

  • (Symbol)

    Current pipeline mode (:strict, :warn, :permissive)



132
133
134
135
136
137
138
139
140
# File 'lib/familia/settings.rb', line 132

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



142
143
144
145
146
147
# File 'lib/familia/settings.rb', line 142

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