Class: Rubot::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/rubot/classes/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_commands_path:, commands_path: nil, events_path: nil) ⇒ Manager

Returns a new instance of Manager.



9
10
11
12
13
# File 'lib/rubot/classes/manager.rb', line 9

def initialize(application_commands_path:, commands_path: nil, events_path: nil)
  @application_commands_path = application_commands_path
  @commands_path = commands_path
  @events_path = events_path
end

Instance Attribute Details

#application_commands_path ⇒ Object

Returns the value of attribute application_commands_path.



7
8
9
# File 'lib/rubot/classes/manager.rb', line 7

def application_commands_path
  @application_commands_path
end

#commands_path ⇒ Object

Returns the value of attribute commands_path.



7
8
9
# File 'lib/rubot/classes/manager.rb', line 7

def commands_path
  @commands_path
end

#events_path ⇒ Object

Returns the value of attribute events_path.



7
8
9
# File 'lib/rubot/classes/manager.rb', line 7

def events_path
  @events_path
end

Instance Method Details

#application_commands_files ⇒ Object



27
28
29
# File 'lib/rubot/classes/manager.rb', line 27

def application_commands_files
  files(@application_commands_path)
end

#commands_files ⇒ Object



31
32
33
# File 'lib/rubot/classes/manager.rb', line 31

def commands_files
  files(@commands_path) if @commands_path
end

#events_files ⇒ Object



35
36
37
# File 'lib/rubot/classes/manager.rb', line 35

def events_files
  files(@events_path) if @events_path
end

#files(path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubot/classes/manager.rb', line 15

def files(path)
  Dir.entries(path).each_with_object([]) do |entry, files|
    next if %w[. ..].include?(entry)

    if Dir.exist?("#{@application_commands_path}/#{entry}")
      files.concat(files("#{path}/#{entry}"))
    else
      files << "#{path}/#{entry}" unless files.include?("#{path}/#{entry}")
    end
  end
end

#load ⇒ Object



39
40
41
42
43
44
# File 'lib/rubot/classes/manager.rb', line 39

def load
  application_commands_files.each { |file| Kernel.load file }
  commands_files&.each { |file| Kernel.load file }
  events_files&.each { |file| Kernel.load file }
  true
end