Sha256: cb57f2a580e20cda9e65b20cf370a565c1c825bb4c429da7b802a23c05425108

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

module Clamp
  module Subcommand

    module Execution

      # override default Command behaviour

      def execute
        # delegate to subcommand
        subcommand = instantiate_subcommand(subcommand_name)
        subcommand.run(subcommand_arguments)
      end

      private

      def instantiate_subcommand(name)
        subcommand_class = find_subcommand_class(name)
        subcommand = subcommand_class.new("#{invocation_path} #{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

      def find_subcommand_class(name)
        subcommand_def = self.class.find_subcommand(name)
        return subcommand_def.subcommand_class if subcommand_def
        subcommand_missing(name)
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clamp-1.1.1 lib/clamp/subcommand/execution.rb
clamp-1.1.0 lib/clamp/subcommand/execution.rb