Class: Zabbirc::Irc::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbirc/irc/base_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ops, message, cmd) ⇒ BaseCommand

Returns a new instance of BaseCommand.



15
16
17
18
19
20
21
# File 'lib/zabbirc/irc/base_command.rb', line 15

def initialize ops, message, cmd
  @ops = ops
  @message = message
  @op = get_op @message
  @cmd = cmd.to_s.strip.gsub(/\s{2,}/," ")
  @args = @cmd.split(/ /)
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



14
15
16
# File 'lib/zabbirc/irc/base_command.rb', line 14

def op
  @op
end

Class Method Details

.register_help(command, description) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/zabbirc/irc/base_command.rb', line 5

def self.register_help command, description
  raise ArgumentError, "command `#{command}` already registered" if HELP_FEATURES.key? command
  HELP_FEATURES[command] = description
end

Instance Method Details

#help_featuresObject



10
11
12
# File 'lib/zabbirc/irc/base_command.rb', line 10

def help_features
  HELP_FEATURES
end

#runObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/zabbirc/irc/base_command.rb', line 23

def run
  return unless authenticated?
  begin
    perform # perform method should be implemented in subclass
  rescue Zabbix::NotConnected => e
    reply "#{e.to_s}"
  rescue UserInputError => e
    reply e.reply_messages
  end
end