Sha256: cc0184610790e2d0ab436ec57c484b9b21fecbdb177a5b5faf130dcc582e51c7

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

require 'thor'
require 'thor/command'

module DLDInternet
  module Thor
    class DynamicCommand < ::Thor::DynamicCommand
      # By default, a command invokes a method in the thor class. You can change this
      # implementation to create custom commands.
      def run(instance, args = [])
        arity = nil

        if private_method?(instance)
          instance.class.handle_no_command_error(name)
        elsif public_method?(instance)
          arity = instance.method(name).arity
          instance.__send__(name, *args)
        elsif local_method?(instance, :method_missing)
          instance.__send__(:method_missing, name.to_sym, *args)
        else
          if instance.class.instance_methods.include?(:handle_no_command_error)
            instance.handle_no_command_error(name)
          else
            instance.class.handle_no_command_error(name)
          end
        end
      rescue ArgumentError => e
        handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e)
      rescue ::Thor::NoMethodError => e
        handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e)
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dldinternet-mixlib-thor-0.9.10 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.9 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.8 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.7 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.6 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.5 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.4 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.3 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.2 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.9.1 lib/dldinternet/thor/dynamic_command.rb
dldinternet-mixlib-thor-0.7.0 lib/dldinternet/thor/dynamic_command.rb