Module: Bcome::ContextFunctions
- Included in:
- Stack::Base
- Defined in:
- lib/context_functions.rb
Constant Summary collapse
- CONFIGS_PATH =
"bcome/config"
Instance Method Summary collapse
- #command_for_context(command) ⇒ Object
- #context_cmd_config_path ⇒ Object
- #context_cmd_functions ⇒ Object
- #context_commands ⇒ Object
- #execute_command_for_context(context_command) ⇒ Object
- #has_context_cmd_functions? ⇒ Boolean
- #has_context_functions_config? ⇒ Boolean
- #load_context_cmd_functions ⇒ Object
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 #{} for command key #{command}" if ccfs.size > 1 return ccfs.first end |
#context_cmd_config_path ⇒ Object
46 47 48 |
# File 'lib/context_functions.rb', line 46 def context_cmd_config_path "#{CONFIGS_PATH}/context_functions.yml" end |
#context_cmd_functions ⇒ Object
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_commands ⇒ Object
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". + "\n" context_cmd_functions.each_with_index do |context_function, index| description += "\n\s\s\s#{index+1}. #{context_function[:description].}" description += "\n\s\s\sExecuted command:". + "\s#{context_function[:executed_command]} bcome_context=\"#{}\"" description += "\n\s\s\sUsage:". + "\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=\"#{}\"" run_local(full_command) end |
#has_context_cmd_functions? ⇒ 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
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_functions ⇒ Object
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[] end |