Module: Bcome::ContextFunctions

Included in:
Stack::Base
Defined in:
lib/context_functions.rb

Constant Summary collapse

CONFIGS_PATH =
"bcome/config"

Instance Method Summary collapse

Instance Method Details

#command_for_context(command) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/context_functions.rb', line 10

def command_for_context(command)
  return false unless context_cmd_functions
  return false if !context_cmd_functions.any?

  ccfs = context_cmd_functions.select{|ccf| ccf[:command].to_s == command.to_s }
  raise "Multiple context commands found at context level #{context_breadcrumb} for command key #{command}" if ccfs.size > 1 
  return ccfs.first
end

#context_cmd_config_pathObject



48
49
50
# File 'lib/context_functions.rb', line 48

def context_cmd_config_path
  "#{CONFIGS_PATH}/context_functions.yml"
end

#context_cmd_functionsObject



34
35
36
37
# File 'lib/context_functions.rb', line 34

def context_cmd_functions
  return [] unless has_context_functions_config?
  @context_cmd_functions ||= load_context_cmd_functions
end

#context_commandsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/context_functions.rb', line 19

def context_commands
  if context_cmd_functions && context_cmd_functions.any?
    puts "\n\n\s\s" + "Context Commands".menu_title_green + "\n\n"
    context_cmd_functions.each_with_index do |context_function, index|
      puts "\n\t#{index+1}. #{context_function[:description].menu_item_green}" + "\n"
      puts "\tExecuted command:".menu_item_cyan + "\s#{context_function[:executed_command]} bcome_context=\"#{context_breadcrumb}\""
      puts "\tUsage:".menu_item_cyan + "\s#{context_function[:command].command}"
      puts
    end
  else
    puts "You don't have any context specific functions defined yet."
  end
  return
end

#execute_command_for_context(context_command) ⇒ Object



5
6
7
8
# File 'lib/context_functions.rb', line 5

def execute_command_for_context(context_command)
  full_command = context_command[:executed_command] + " bcome_context=\"#{context_breadcrumb}\""
  run_local(full_command)
end

#has_context_cmd_functions?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/context_functions.rb', line 39

def has_context_cmd_functions?
  !context_cmd_functions.nil?
end

#has_context_functions_config?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/context_functions.rb', line 52

def has_context_functions_config?
  File.exist?(context_cmd_config_path)
end

#load_context_cmd_functionsObject



43
44
45
46
# File 'lib/context_functions.rb', line 43

def load_context_cmd_functions
  configs = YAML.load_file(context_cmd_config_path)
  return configs[context_breadcrumb]
end