module Clamp::Subcommand::Execution

Public Instance Methods

execute() click to toggle source

override default Command behaviour

# File lib/clamp/subcommand/execution.rb, line 8
def execute
  # delegate to subcommand
  subcommand = instantiate_subcommand(subcommand_name)
  subcommand.run(subcommand_arguments)
end

Private Instance Methods

find_subcommand_class(name) click to toggle source
# File lib/clamp/subcommand/execution.rb, line 31
def find_subcommand_class(name)
  subcommand_def = self.class.find_subcommand(name)
  return subcommand_def.subcommand_class if subcommand_def
  subcommand_missing(name)
end
instantiate_subcommand(name) click to toggle source
# File lib/clamp/subcommand/execution.rb, line 16
def instantiate_subcommand(name)
  subcommand_class = find_subcommand_class(name)
  subcommand = subcommand_class.new(invocation_path_for(name), context)
  self.class.inheritable_attributes.each do |attribute|
    next unless attribute.of(self).defined?
    attribute.of(subcommand).set(attribute.of(self).get)
  end
  subcommand
end
invocation_path_for(name) click to toggle source
# File lib/clamp/subcommand/execution.rb, line 26
def invocation_path_for(name)
  param_names = self.class.inheritable_parameters.map(&:name)
  [invocation_path, *param_names, name].join(" ")
end