Class: Redde::SystemCommand

Inherits:
Object
  • Object
show all
Defined in:
app/models/redde/system_command.rb

Constant Summary collapse

ALLOWED_ACTIONS =
%w(cache unicorn sidekiq reboot).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ SystemCommand

Returns a new instance of SystemCommand.



10
11
12
13
14
# File 'app/models/redde/system_command.rb', line 10

def initialize(action)
  @action = action
  Logger.new('log/commands.log').info "Received #{action} command"
  fail "Unsopported command #{action}. Allowed commands: #{ALLOWED_ACTIONS.join(', ')}" unless ALLOWED_ACTIONS.include?(action.to_s)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



2
3
4
# File 'app/models/redde/system_command.rb', line 2

def action
  @action
end

Class Method Details

.execute(action) ⇒ Object



6
7
8
# File 'app/models/redde/system_command.rb', line 6

def self.execute(action)
  new(action).process
end

Instance Method Details

#processObject



16
17
18
# File 'app/models/redde/system_command.rb', line 16

def process
  send(action)
end