Sha256: eb5997008cf533851ffc939b38bcd35b4a7d957a8d27e78dbb2b9a6ec7856253
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
# frozen_string_literal: true module Commande class Chain include Commande output :chain_result def initialize(*commands) self.commands = commands end def chain(*commands) new(*self.commands, *commands) end def valid(**_args) error! 'needs at least one command' if commands.empty? true end def call(**args) self.chain_result = commands.inject(InitialCommandResult.new(args)) do |last_result, current_command| current_result = current_command.call(**last_result.payload.dup) transfer_logs current_result transfer_errors current_result fail! unless transfer_success? current_result current_result end end private attr_accessor :commands, :chain_result class InitialCommandResult def initialize(**args) self.payload = args end attr_reader :payload private attr_writer :payload end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
commande-0.4.1 | lib/commande/chain.rb |
commande-0.4.0 | lib/commande/chain.rb |