Module: Familia::Features::TransientFields::ClassMethods

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

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

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

Define a transient field that automatically wraps values in RedactedString

Examples:

Define a transient API key field

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

Parameters:

  • name (Symbol)

    The field name

  • as (Symbol) (defaults to: name)

    The method name (defaults to field name)

  • kwargs (Hash)

    Additional field options



34
35
36
37
38
39
40
41
# File 'lib/familia/features/transient_fields.rb', line 34

def transient_field(name, as: name, **kwargs)
  # Use the field type system - much cleaner than alias_method approach!
  # We can now remove the transient_field method from this feature entirely
  # since it's built into DefinitionMethods using TransientFieldType
  require_relative 'transient_fields/transient_field_type'
  field_type = TransientFieldType.new(name, as: as, **kwargs.merge(fast_method: false))
  register_field_type(field_type)
end