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, arguments = []) ⇒ Object
- #has_context_cmd_functions? ⇒ Boolean
- #has_context_functions_config? ⇒ Boolean
- #load_context_cmd_functions ⇒ Object
Instance Method Details
#command_for_context(command) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/context_functions.rb', line 21 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
57 58 59 |
# File 'lib/context_functions.rb', line 57 def context_cmd_config_path "#{CONFIGS_PATH}/context_functions.yml" end |
#context_cmd_functions ⇒ Object
43 44 45 46 |
# File 'lib/context_functions.rb', line 43 def context_cmd_functions return [] unless has_context_functions_config? @context_cmd_functions ||= load_context_cmd_functions end |
#context_commands ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/context_functions.rb', line 30 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, arguments = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/context_functions.rb', line 5 def execute_command_for_context(context_command, arguments = []) arguments.flatten! if arguments.any? && context_command[:executed_command_with_args] raw_command = context_command[:executed_command_with_args] arguments.each_with_index {|argument, index | raw_command.gsub!("%#{index+1}%",argument) } full_command = raw_command else full_command = context_command[:executed_command] end full_command += " bcome_context=\"#{}\"" run_local(full_command) end |
#has_context_cmd_functions? ⇒ Boolean
48 49 50 |
# File 'lib/context_functions.rb', line 48 def has_context_cmd_functions? !context_cmd_functions.nil? end |
#has_context_functions_config? ⇒ Boolean
61 62 63 |
# File 'lib/context_functions.rb', line 61 def has_context_functions_config? File.exist?(context_cmd_config_path) end |
#load_context_cmd_functions ⇒ Object
52 53 54 55 |
# File 'lib/context_functions.rb', line 52 def load_context_cmd_functions configs = YAML.load_file(context_cmd_config_path) return configs[] end |