Sha256: ac04e608932d95d3ae06dca6fdcdbc9992af2c6bfe3d2ffee3e4a55fcbf0bcd7

Contents?: true

Size: 784 Bytes

Versions: 9

Compression:

Stored size: 784 Bytes

Contents

require 'result'

module Railway
  include Result::DSL

  module DSL
    def step(name, options = {})
      with = options.delete(:with)
      steps.push(:name => name, :with => with)
    end

    def steps
      @steps ||= []
    end
  end

  def self.included(base)
    base.send :extend, DSL
  end

  def call(input = {})
    steps = self.class.steps

    return Failure('No steps') if steps.empty?

    steps.
      inject(Success(input)) {|result, step|
        result.and_then {|data|
          dispatch_step(step, data)
        }
      }
  end

  private
  def dispatch_step(step, data)
    begin
      result = (step[:with] || self).send(step[:name], data)
      result.is_a?(Result::Base) ? result : Success(result)
    rescue => error
      Failure(error)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
engineyard-serverside-3.0.4 lib/railway.rb
engineyard-serverside-3.0.3 lib/railway.rb
engineyard-serverside-2.8.0 lib/railway.rb
engineyard-serverside-2.8.0.pre4 lib/railway.rb
engineyard-serverside-2.8.0.pre3 lib/railway.rb
engineyard-serverside-2.8.0.pre2 lib/railway.rb
engineyard-serverside-2.8.0.pre lib/railway.rb
engineyard-serverside-2.7.0.pre lib/railway.rb
engineyard-serverside-2.6.19 lib/railway.rb