Sha256: d9fae332030a37804f63520150e0aade85b7cd6e3c3c0d445bcbdbf1d504da10

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

module Gator
  module Command

    class << self

      def add(command)
        unless will_collide? command
          commands.push(command)
          return true
        end
        false
      end

      def remove(command)
        commands.delete(command) != nil?
      end

      def has?(name_or_alias)
        commands.any? { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
      end

      def get(name_or_alias)
        commands.detect { |command| command.command_name == name_or_alias || command.command_alias == name_or_alias }
      end

      protected

      def commands
        @commands ||= []
      end

      def will_collide?(command)
        has?(command.command_name) || has?(command.command_alias)
      end

    end

    class Base < Thor::Group

      class << self
        attr_reader :command_name, :command_alias

        def specify( command_name, command_alias )
          @command_name, @command_alias = command_name, command_alias
        end
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gator-0.0.8.pre lib/__legacy/core/command/command.rb
gator-0.0.7.pre lib/__legacy/core/command/command.rb
gator-0.0.6.pre lib/__legacy/core/command/command.rb
gator-0.0.5.pre lib/core/command/command.rb