Class: Morpher::Transform::Sequence

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

Overview

Sequence of transformations

Instance Method Summary collapse

Methods inherited from Morpher::Transform

#array, #maybe, #slug, #to_proc

Instance Method Details

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

Apply transformation to input

Parameters:

  • (Object)

Returns:



465
466
467
468
469
470
471
472
473
474
475
# File 'lib/morpher/transform.rb', line 465

def call(input)
  current = input

  steps.each_with_index do |step, index|
    current = step.call(current).from_right do |error|
      return failure(error(cause: Index.wrap(error, index), input: input))
    end
  end

  success(current)
end

#seq(transform) ⇒ Transform

Build sequence

Parameters:

Returns:



456
457
458
# File 'lib/morpher/transform.rb', line 456

def seq(transform)
  self.class.new(steps + [transform])
end