Module: Remap::State

Includes:
Dry::Core::Constants
Defined in:
lib/remap/state.rb,
lib/remap/state/schema.rb,
lib/remap/state/extension.rb

Overview

Represents the current state of a mapping

Defined Under Namespace

Modules: Extension Classes: Dummy

Constant Summary collapse

Schema =
Dry::Schema.define do
  required(:input)

  required(:mapper).filled(Remap::Types::Mapper)
  required(:notices).array(Types.Instance(Notice))
  required(:options).value(:hash)
  required(:path).array(Types::Key)

  optional(:index).filled(:integer)
  optional(:element).filled
  optional(:key).filled

  optional(:scope)
  optional(:value)
end

Class Method Summary collapse

Class Method Details

.call(value, mapper: Dummy, options: EMPTY_HASH) ⇒ Hash

Creates a valid state

Parameters:

  • value (Any)

    Internal state value

  • mapper (Hash) (defaults to: Dummy)

    a customizable set of options

  • options (Hash) (defaults to: EMPTY_HASH)

    a customizable set of options

Options Hash (mapper:):

  • Mapper (Mapper::Class)

    class

Options Hash (options:):

  • Mapper (Hash)

    options / arguments

Returns:

  • (Hash)

    A valid state

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/remap/state.rb', line 32

def self.call(value, mapper: Dummy, options: EMPTY_HASH)
  value._ do
    return {
      notices: EMPTY_ARRAY,
      path: EMPTY_ARRAY,
      options: options,
      mapper: mapper,
      values: value,
      value: value,
      input: value
    }._
  end

  raise ArgumentError, "Input is a state: #{value}"
end