Class: ComponentsList

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/util/components_list.rb

Overview

Utility methods to list components

Class Method Summary collapse

Class Method Details

.components_in_dir(dir) ⇒ Object

Returns all the components in a certain directory



5
6
7
# File 'lib/commands/util/components_list.rb', line 5

def self.components_in_dir( dir )
  Dir.entries(dir).select {|entry| File.directory?(File.join(dir, entry)) && !(entry =='.' || entry == '..') }
end

.for_each_component_in_dir(dir) {|component| ... } ⇒ Object

Executes a code block for each component in a certain directory

Parameters:

  • dir (String)

    directory where we are iterating

Yields:

  • (component)

    Passes the component name to the block



13
14
15
# File 'lib/commands/util/components_list.rb', line 13

def self.for_each_component_in_dir( dir, &block )
  components_in_dir(dir).each { |component| block.call component }
end

.run_level_bots_list(app_path, params) ⇒ Object

Returns the list of run-level bots for this run Depending on the mode we are in, we want to start only some bots, exclude only some bots or start all bots



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/commands/util/components_list.rb', line 20

def self.run_level_bots_list( app_path, params )
  # Fetch the list of all components in the bots dir
  all_bots = components_in_dir "#{app_path}/bots/"
  # Fetch the list of app bots
  app_bots = Nutella.current_app.config['app_bots']
  # Return correct list based on the mode we are in
  case start_mode(params)
    when :WITH
      return  get_with_bots_list params[:with], app_bots
    when :WO
      return get_wo_bots_list all_bots, app_bots, params[:without]
    when :ALL
      return get_all_bots_list all_bots, app_bots
    else
      # If we get here it means we are both in with and without mode and something went very wrong...
      raise 'You are using simultaneously with and without modes. This should not happen. Please contact developers.'
  end
end