Class: Morpher::Transform::Primitive

Inherits:
Morpher::Transform show all
Defined in:
lib/morpher/transform.rb

Overview

Transform guarding a specific primitive

Constant Summary collapse

MESSAGE =
'Expected: %<expected>s but got: %<actual>s'

Instance Method Summary collapse

Methods inherited from Morpher::Transform

#array, #maybe, #seq, #to_proc

Instance Method Details

#call(input) ⇒ Either<Error, Object>

Apply transformation to input

Parameters:

  • input (Object)

Returns:



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/morpher/transform.rb', line 214

def call(input)
  if input.instance_of?(primitive)
    success(input)
  else
    failure(
      error(
        input:   input,
        message: MESSAGE % { actual: input.class, expected: primitive }
      )
    )
  end
end

#slugString

Rendering slug

Returns:

  • (String)


230
231
232
# File 'lib/morpher/transform.rb', line 230

def slug
  primitive.to_s
end