class Neco::Container
Container
has two purposes. One is to store commands and execute rollbacks when one command raises an exception. Another is to store environment hash for those commands so that commands can pass data between them.
Public Class Methods
new(commands: [], environment: {})
click to toggle source
# File lib/neco/container.rb, line 8 def initialize(commands: [], environment: {}) @commands = commands.map {|command| command.new(container: self) } @environment = environment @called = [] end
Public Instance Methods
call(*args, **params)
click to toggle source
# File lib/neco/container.rb, line 14 def call(*args, **params) @environment.merge!(params) @commands.each do |command| result = command.call(*args, **@environment) if result.success? @called << command else @called.reverse_each(&:revert) break end end end
set(key, value)
click to toggle source
# File lib/neco/container.rb, line 27 def set(key, value) @environment[key] = value end