Sha256: f6d65bf2310538e362c88470a59e7109961d7946541758a170a64fe072d1917f

Contents?: true

Size: 838 Bytes

Versions: 12

Compression:

Stored size: 838 Bytes

Contents

module Datacaster
  class AroundNode < Base
    def initialize(around = nil, &block)
      raise "Expected block" unless block_given?

      @around = around
      @run = block
    end

    def around(*casters)
      if @around
        raise ArgumentError, "only one call to .around(...) is expect, tried to call second time", caller
      end

      unless casters.all? { |x| Datacaster.instance?(x) }
        raise ArgumentError, "provide datacaster instance to .around(...)", caller
      end

      caster = casters.length == 1 ? casters[0] : Datacaster::Predefined.steps(*casters)

      self.class.new(caster, &@run)
    end

    def cast(object, runtime:)
      unless @around
        raise ArgumentError, "call .around(caster) beforehand", caller
      end
    end

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/around_node.rb
datacaster-4.0.1 lib/datacaster/around_node.rb
datacaster-3.3.1 lib/datacaster/around_node.rb
datacaster-3.3.0 lib/datacaster/around_node.rb
datacaster-3.2.7 lib/datacaster/around_node.rb
datacaster-3.2.6 lib/datacaster/around_node.rb
datacaster-3.2.5 lib/datacaster/around_node.rb
datacaster-3.2.4 lib/datacaster/around_node.rb
datacaster-3.2.3 lib/datacaster/around_node.rb
datacaster-3.2.2 lib/datacaster/around_node.rb
datacaster-3.2.1 lib/datacaster/around_node.rb
datacaster-3.2.0 lib/datacaster/around_node.rb