Module: GL::Chain
- Defined in:
- lib/gl/command/chain.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/gl/command/chain.rb', line 5 def self.included(base) base.class_eval do extend ClassMethods @commands = [] end end |
Instance Method Details
#call_command(command) ⇒ Object
42 43 44 45 46 |
# File 'lib/gl/command/chain.rb', line 42 def call_command(command) @commands_called << command @context = command.call(@context) raise ContextFailure if @context.failure? end |
#commands ⇒ Object
23 24 25 |
# File 'lib/gl/command/chain.rb', line 23 def commands self.class.commands end |
#perform ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/gl/command/chain.rb', line 27 def perform run_callbacks :call do @commands_called = [] commands.each { |command| call_command(command) } end rescue ContextFailure rollback end |
#rollback ⇒ Object
36 37 38 39 40 |
# File 'lib/gl/command/chain.rb', line 36 def rollback @commands_called.reverse_each do |command| command.new(@context).rollback end end |