Class: Pechkin::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/command/base.rb

Overview

Basic class for all commands

Direct Known Subclasses

AddAuth, Check, List, RunServer, SendData

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, stdout: $stdout, stderr: $stderr) ⇒ Base

Initializes command state

Parameters:

  • options (OpenStruct)

    set of options which allows to configure command behaviour



12
13
14
15
16
# File 'lib/pechkin/command/base.rb', line 12

def initialize(options, stdout: $stdout, stderr: $stderr)
  @options = options
  @stdout = stdout
  @stderr = stderr
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/pechkin/command/base.rb', line 5

def options
  @options
end

Instance Method Details

#configurationObject



18
19
20
21
# File 'lib/pechkin/command/base.rb', line 18

def configuration
  config_dir = options.config_dir
  @configuration ||= Configuration.load_from_directory(config_dir)
end

#handlerObject



23
24
25
# File 'lib/pechkin/command/base.rb', line 23

def handler
  @handler ||= Handler.new(configuration.channels)
end

#matches?Boolean

Returns:

  • (Boolean)


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

def matches?
  raise 'Unimplemented'
end

#puts(*args) ⇒ Object



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

def puts(*args)
  @stdout.puts(*args)
end

#warn(*args) ⇒ Object



35
36
37
# File 'lib/pechkin/command/base.rb', line 35

def warn(*args)
  @stderr.puts(*args)
end