Sha256: 34c2695b89ae1a48a6270cc1fa642ddffe73e66378be18d7539a80b2908acd8f

Contents?: true

Size: 787 Bytes

Versions: 18

Compression:

Stored size: 787 Bytes

Contents

module Datacaster
  class ContextNode < Base
    def initialize(base)
      @base = base
    end

    def cast(object, runtime:)
      @runtime = create_runtime(runtime)
      result = @base.with_runtime(@runtime).call(object)
      transform_result(result)
    end

    def inspect
      "#<#{self.class.name} base: #{@base.inspect}>"
    end

    private

    def create_runtime(parent)
      parent
    end

    def runtime
      @runtime
    end

    def transform_result(result)
      if result.valid?
        Datacaster.ValidResult(transform_success(result.value))
      else
        Datacaster.ErrorResult(transform_errors(result.raw_errors))
      end
    end

    def transform_success(value)
      value
    end

    def transform_errors(errors)
      errors
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/context_node.rb
datacaster-4.0.1 lib/datacaster/context_node.rb
datacaster-3.3.1 lib/datacaster/context_node.rb
datacaster-3.3.0 lib/datacaster/context_node.rb
datacaster-3.2.7 lib/datacaster/context_node.rb
datacaster-3.2.6 lib/datacaster/context_node.rb
datacaster-3.2.5 lib/datacaster/context_node.rb
datacaster-3.2.4 lib/datacaster/context_node.rb
datacaster-3.2.3 lib/datacaster/context_node.rb
datacaster-3.2.2 lib/datacaster/context_node.rb
datacaster-3.2.1 lib/datacaster/context_node.rb
datacaster-3.2.0 lib/datacaster/context_node.rb
datacaster-3.1.5 lib/datacaster/context_node.rb
datacaster-3.1.3 lib/datacaster/context_node.rb
datacaster-3.1.2 lib/datacaster/context_node.rb
datacaster-3.1.1 lib/datacaster/context_node.rb
datacaster-3.1.0 lib/datacaster/context_node.rb
datacaster-3.0.0 lib/datacaster/context_node.rb