Module: Adama::Command

Defined in:
lib/adama/command.rb

Overview

Extend class with module methods

class CollectUnderpantsCommand

include Adama::Command

def call
  got_get_underpants()
end

def rollback
  return_underpants_to_rightful_owner()
end

end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Internal: Install Command’s behavior in the given class.



17
18
19
20
21
22
23
# File 'lib/adama/command.rb', line 17

def self.included(base)
  base.class_eval do
    prepend Validator
    extend ClassMethods
    attr_reader :kwargs
  end
end

Instance Method Details

#callObject

Public instance method. Override this in classes this module is included in.



50
# File 'lib/adama/command.rb', line 50

def call; end

#initialize(**kwargs) ⇒ Object



32
33
34
# File 'lib/adama/command.rb', line 32

def initialize(**kwargs)
  @kwargs = kwargs
end

#rollbackObject

Public instance method. Override this in classes this module is included in.



54
# File 'lib/adama/command.rb', line 54

def rollback; end

#runObject

Internal instance method. Called by both the call class method, and by the call method in the invoker. If it fails it raises a CommandError.



38
39
40
41
42
43
44
45
46
# File 'lib/adama/command.rb', line 38

def run
  tap(&:call)
rescue => error
  raise Errors::CommandError.new(
    error: error,
    command: self,
    backtrace: error.backtrace
  )
end