Sha256: dabe8c767f990d9610145a0a40594096eb2be2531ea437901071a93734c4f80e

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

module WIP
  module Runner
    module Commands
      class << self
        def locate(name, namespace = nil)
          return nil if name.nil? || name.match(/^-/)

          command    = name.split('-').map(&:capitalize).join
          namespaces = namespace ? [namespace] : [explicit, implicit]
          namespaces.each do |ns|
            return ns.const_get(command) if ns && ns.const_defined?(command)
          end
          raise InvalidCommand, name
        end

        def within(namespace)
          return [] if namespace.nil?

          namespace.constants
            .collect { |const|
              namespace.const_get(const)
            }
            .select { |command|
              command < Command # is a subclass of
            }
        end

        def implicit
          WIP::Runner::CLI
        end

        def explicit
          @explicit ||= begin
            namespace.const_get(:Commands) if namespace.const_defined?(:Commands)
          end
        end

        def namespace
          WIP::Runner::CLI.namespace
        end
      end
    end
  end
end

# NOTE: Commands are responsible for requiring sub-commands.
Dir[File.expand_path('../commands/*.rb', __FILE__)].each { |f| require(f) }

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
wip-runner-0.4.1 lib/wip/runner/commands.rb
wip-runner-0.4.0 lib/wip/runner/commands.rb
wip-runner-0.3.4 lib/wip/runner/commands.rb
wip-runner-0.3.3 lib/wip/runner/commands.rb
wip-runner-0.3.2 lib/wip/runner/commands.rb
wip-runner-0.3.1 lib/wip/runner/commands.rb
wip-runner-0.3.0 lib/wip/runner/commands.rb
wip-runner-0.2.1 lib/wip/runner/commands.rb
wip-runner-0.2.0 lib/wip/runner/commands.rb
wip-runner-0.1.0 lib/wip/runner/commands.rb