class CLIChef::Cookbook
Public Class Methods
ingredient(name)
click to toggle source
# File lib/cli_chef/components/cookbook.rb, line 87 def self.ingredient(name) ingredients.find { |i| i.match?(name) } end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/cli_chef/components/cookbook.rb, line 79 def self.method_missing(method, *args, &block) prototype.respond_to?(method) ? prototype.send(method, *args, &block) : super end
prototype()
click to toggle source
# File lib/cli_chef/components/cookbook.rb, line 75 def self.prototype @prototype ||= self.new end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/cli_chef/components/cookbook.rb, line 83 def self.respond_to_missing?(method, include_private = false) prototype.respond_to?(method) || super end
Public Instance Methods
execute(string, opts = {}, &block)
click to toggle source
Executes a string as a command to this CLI wrapper in a job (threaded)
# File lib/cli_chef/components/cookbook.rb, line 25 def execute(string, opts = {}, &block) raise RuntimeError, "A valid path is currently not set for #{self.class}. Please set a valid path to the executable first." unless path return execute!(string, opts.except(:synchronous), &block) if opts[:synchronous] string = "#{clean_path} #{string}" BBLib.logger.debug("About to run cmd: #{string}") (opts.delete(:job_class) || default_job_class).new(opts.merge(command: string, parent: self)).tap do |job| job.run(&block) end end
execute!(string, opts = {}, &block)
click to toggle source
Synchonous version of execute
# File lib/cli_chef/components/cookbook.rb, line 36 def execute!(string, opts = {}, &block) while (job ||= execute(string, opts, &block)).running? # Nothing end job.result end
prepare(**args)
click to toggle source
Returns the full command line that would be run based on the given arguments
# File lib/cli_chef/components/cookbook.rb, line 57 def prepare(**args) "#{clean_path} #{prepare_args(args)}" end
prepare_args(**args)
click to toggle source
# File lib/cli_chef/components/cookbook.rb, line 61 def prepare_args(**args) args.map do |name, arg| ingredient = self.ingredient(name) raise ArgumentError, "Unknown parameter #{name} for #{self.class}." unless ingredient ingredient.to_s(arg) end.join(' ') end
ready?()
click to toggle source
Returns true if the path is either set to a valid file or can be found in the environment
# File lib/cli_chef/components/cookbook.rb, line 20 def ready? path && (File.exist?(path) || BBLib::OS.which(path)) end
run(**args, &block)
click to toggle source
Runs a command within a Job
(seperate thread) For when a command should be run asynchronously
# File lib/cli_chef/components/cookbook.rb, line 45 def run(**args, &block) return run!(args.except(:synchronous), &block) if args[:synchronous] execute(prepare_args(args), &block) end
run!(**args, &block)
click to toggle source
Blocking version of run that is not executed within a thread. For when a command should be run synchronously
# File lib/cli_chef/components/cookbook.rb, line 52 def run!(**args, &block) execute!(prepare_args(args), &block) end
Protected Instance Methods
check_default_locations()
click to toggle source
# File lib/cli_chef/components/cookbook.rb, line 93 def check_default_locations return if @path return unless found = default_locations.find { |path| File.exist?(path) || BBLib::OS.which(path) } self.path = found end
clean_path()
click to toggle source
# File lib/cli_chef/components/cookbook.rb, line 99 def clean_path path.to_s.match?(/\s/) ? "\"#{path}\"" : path end