Class: BaseCommandHandler

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

Direct Known Subclasses

CommandHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BaseCommandHandler

Returns a new instance of BaseCommandHandler.



35
36
37
38
39
40
41
42
43
44
# File 'lib/advanced_ruby_command_handler/base.rb', line 35

def initialize(options)
  %i[commands_dir events_dir commands_module_name events_module_name].each do |dir|
    raise Errors::MissingParameter.new(dir, "Parameter '#{dir}' unspecified") unless options[dir]
  end
  @commands_dir = options[:commands_dir]
  @events_dir = options[:events_dir]
  @commands_module_name = options[:commands_module_name]
  @events_module_name = options[:events_module_name]
  FileUtils.mkdir_p [@commands_dir, @events_dir]
end

Instance Attribute Details

#commands_dirObject

Returns the value of attribute commands_dir.



32
33
34
# File 'lib/advanced_ruby_command_handler/base.rb', line 32

def commands_dir
  @commands_dir
end

#commands_module_nameObject (readonly)

Returns the value of attribute commands_module_name.



33
34
35
# File 'lib/advanced_ruby_command_handler/base.rb', line 33

def commands_module_name
  @commands_module_name
end

#events_dirObject

Returns the value of attribute events_dir.



32
33
34
# File 'lib/advanced_ruby_command_handler/base.rb', line 32

def events_dir
  @events_dir
end

#events_module_nameObject (readonly)

Returns the value of attribute events_module_name.



33
34
35
# File 'lib/advanced_ruby_command_handler/base.rb', line 33

def events_module_name
  @events_module_name
end

Instance Method Details

#get_module_by_string(module_name) ⇒ Object



46
47
48
49
50
# File 'lib/advanced_ruby_command_handler/base.rb', line 46

def get_module_by_string(module_name)
  raise Errors::NonExistingModule.new(module_name, "Module '#{module_name}' doesn't exist. Please specify an existing module") unless Object.const_defined?(module_name)

  Object.const_get(module_name)
end