Module: GL::Command

Defined in:
lib/gl/command/base.rb,
lib/gl/command/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/gl/command/base.rb', line 5

def self.included(base)
  base.class_eval do
    include ActiveSupport::Callbacks
    extend ClassMethods

    define_callbacks :call
    attr_reader :context
  end
end

Instance Method Details

#initialize(context = {}) ⇒ Object



27
28
29
# File 'lib/gl/command/base.rb', line 27

def initialize(context = {})
  @context = Context.factory(context)
end

#performObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gl/command/base.rb', line 31

def perform
  run_callbacks :call do
    call
  end
rescue ContractFailure
  context.fail!
  rollback
rescue StandardError => e
  context.fail!
  context.errors.add(:base, e)
  rollback
end

#rollbackObject



44
# File 'lib/gl/command/base.rb', line 44

def rollback; end