Class: ActiveCrew::Base

Inherits:
Object
  • Object
show all
Includes:
Authorizable, Chainable, Combinable, Commandable, Lockable, Measurable, Respondable, Validatable
Defined in:
lib/active_crew/base.rb

Overview

Sidekiq Command class. Implements command pattern for Sidekiq. Helps to deconstruct application into micro services with command interface.

Command class file structure with two micro services (mailer and users):

app
  commands
    mailer
      deliver_command.rb
    users
      create_command.rb

Command queues will be the following:

mailer
users

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commandable

#backend, #command

Methods included from Chainable

#chain, #commands

Methods included from Combinable

#combine_command, #combine_commands

Methods included from Validatable

#validate!

Methods included from Respondable

#respond_fail, #respond_with

Methods included from Authorizable

#can_execute?

Methods included from Lockable

#lock, #locked?

Constructor Details

#initialize(invoker, context = {}) ⇒ Base

Returns a new instance of Base.



33
34
35
36
37
38
# File 'lib/active_crew/base.rb', line 33

def initialize(invoker, context = {})
  @invoker = invoker
  # Should only symbolize key for
  @context = ActiveSupport::HashWithIndifferentAccess.new context
  @options = @context[:options] || {}
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



31
32
33
# File 'lib/active_crew/base.rb', line 31

def context
  @context
end

#invokerObject (readonly)

Returns the value of attribute invoker.



31
32
33
# File 'lib/active_crew/base.rb', line 31

def invoker
  @invoker
end

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/active_crew/base.rb', line 31

def options
  @options
end

Instance Method Details

#executeObject



44
45
46
# File 'lib/active_crew/base.rb', line 44

def execute
  perform
end

#nameObject



40
41
42
# File 'lib/active_crew/base.rb', line 40

def name
  @name ||= self.class.name.underscore.gsub(/_command/, '')
end

#performObject



48
49
# File 'lib/active_crew/base.rb', line 48

def perform
end