Module: Familia::Features::TransientFields::ModelClassMethods

Defined in:
lib/familia/features/transient_fields.rb

Instance Method Summary collapse

Instance Method Details

#transient_field(name, as: name, **kwargs) ⇒ Object

Define a transient field that automatically wraps values in RedactedString

Transient fields are not persisted to Redis/Valkey and exist only in memory. All values are automatically wrapped in RedactedString for security.

Examples:

Define a transient API key field

class Service < Familia::Horreum
  feature :transient_fields
  transient_field :api_key
end

Define a transient field with custom accessor name

class Service < Familia::Horreum
  feature :transient_fields
  transient_field :secret_key, as: :api_secret
end

service = Service.new(secret_key: 'secret123')
service.api_secret.expose { |key| use_api_key(key) }

Parameters:

  • name (Symbol)

    The field name

  • as (Symbol) (defaults to: name)

    The method name (defaults to field name)

  • kwargs (Hash)

    Additional field options



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/familia/features/transient_fields.rb', line 145

def transient_field(name, as: name, **kwargs)
  @transient_fields ||= []
  @transient_fields << name unless @transient_fields.include?(name)

  # Add to field_groups if the group exists
  if field_groups&.key?(:transient_fields)
    field_groups[:transient_fields] << name
  end

  # Use the field type system for proper integration
  field_type = TransientFieldType.new(name, as: as, **kwargs.merge(fast_method: false))
  register_field_type(field_type)
end

#transient_field?(field_name) ⇒ Boolean

Check if a field is transient

Parameters:

  • field_name (Symbol)

    The field name to check

Returns:

  • (Boolean)

    true if field is transient, false otherwise



172
173
174
# File 'lib/familia/features/transient_fields.rb', line 172

def transient_field?(field_name)
  transient_fields.include?(field_name.to_sym)
end

#transient_fieldsArray<Symbol>

Returns list of transient field names defined on this class

Returns:

  • (Array<Symbol>)

    Array of transient field names



163
164
165
# File 'lib/familia/features/transient_fields.rb', line 163

def transient_fields
  @transient_fields || []
end