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



46
47
48
# File 'lib/context_functions.rb', line 46

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

#context_cmd_functionsObject



32
33
34
35
# File 'lib/context_functions.rb', line 32

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
# File 'lib/context_functions.rb', line 19

def context_commands
  if context_cmd_functions && context_cmd_functions.any?
    description = "\n\s\s" + "Context Commands".menu_title_green + "\n"
    context_cmd_functions.each_with_index do |context_function, index|
      description += "\n\s\s\s#{index+1}. #{context_function[:description].menu_item_green}"
      description += "\n\s\s\sExecuted command:".menu_item_cyan + "\s#{context_function[:executed_command]} bcome_context=\"#{context_breadcrumb}\""
      description += "\n\s\s\sUsage:".menu_item_cyan + "\s#{context_function[:command].command}"
      description += "\n"
    end
  end
  return description
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)


37
38
39
# File 'lib/context_functions.rb', line 37

def has_context_cmd_functions?
  !context_cmd_functions.nil?
end

#has_context_functions_config?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/context_functions.rb', line 50

def has_context_functions_config?
  File.exist?(context_cmd_config_path)
end

#load_context_cmd_functionsObject



41
42
43
44
# File 'lib/context_functions.rb', line 41

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