Class: LazyLazer::KeyMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_lazer/key_metadata.rb

Overview

Simple PORO for key metadata. Yay value objects!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_key:, required:, runtime_required:, default:, transform:) ⇒ KeyMetadata

Create a new KeyMetadata value object with all the properties.

Parameters:

  • source_key (Symbol)

    the key to fetch the value from

  • required (Boolean)

    whether the key must exist when creating the model

  • runtime_required (Boolean)

    whether the key must exist when loaded

  • default (Proc, Object)

    the default value or generator

  • transform (Proc, Symbol, nil)

    the method or proc that transforms the return value



23
24
25
26
27
28
29
30
# File 'lib/lazy_lazer/key_metadata.rb', line 23

def initialize(source_key:, required:, runtime_required:, default:, transform:)
  @source_key = source_key
  @required = required
  @runtime_required = runtime_required
  @default = default
  @transform = transform
  freeze
end

Instance Attribute Details

#defaultProc, Object (readonly)

Returns the default value or generator

Returns:

  • (Proc, Object)

    the default value or generator



12
13
14
# File 'lib/lazy_lazer/key_metadata.rb', line 12

def default
  @default
end

#source_keySymbol (readonly)

Returns the key to fetch the value from

Returns:

  • (Symbol)

    the key to fetch the value from



9
10
11
# File 'lib/lazy_lazer/key_metadata.rb', line 9

def source_key
  @source_key
end

#transformProc, ... (readonly)

Returns the method or proc that transforms the return value

Returns:

  • (Proc, Symbol, nil)

    the method or proc that transforms the return value



15
16
17
# File 'lib/lazy_lazer/key_metadata.rb', line 15

def transform
  @transform
end

Instance Method Details

#required?Boolean

Returns whether the key must exist when creating the model

Returns:

  • (Boolean)

    whether the key must exist when creating the model



33
34
35
# File 'lib/lazy_lazer/key_metadata.rb', line 33

def required?
  @required
end

#runtime_required?Boolean

Returns whether the key must exist when loaded

Returns:

  • (Boolean)

    whether the key must exist when loaded



38
39
40
# File 'lib/lazy_lazer/key_metadata.rb', line 38

def runtime_required?
  @runtime_required
end