Sha256: 40a8cca6043d9f0befa296d5161978665a7b18222c3b337e02fb39d9283dedb8

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

module Compass::Commands
  module Registry
    def register(name, command_class)
      @commands ||= Hash.new
      @commands[name.to_sym] = command_class
    end
    def get(name)
      return unless name
      @commands ||= Hash.new
      @commands[name.to_sym] || @commands[abbreviation_of(name)]
    end
    def abbreviation_of(name)
      re = /^#{Regexp.escape(name)}/
      matching = @commands.keys.select{|k| k.to_s =~ re}
      if matching.size == 1
        matching.first
      elsif name =~ /^-/
        nil
      else
        raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}"
      end
    end
    def abbreviation?(name)
      re = /^#{Regexp.escape(name)}/
      @commands.keys.detect{|k| k.to_s =~ re}
    end
    def command_exists?(name)
      @commands ||= Hash.new
      name && (@commands.has_key?(name.to_sym) || abbreviation?(name))
    end
    def all
      @commands.keys
    end
    alias_method :[], :get
    alias_method :[]=, :register
  end
  extend Registry
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
compass-0.11.2 lib/compass/commands/registry.rb
compass-0.11.1 lib/compass/commands/registry.rb
compass-0.11.0 lib/compass/commands/registry.rb
compass-0.11.beta.7 lib/compass/commands/registry.rb
compass-0.11.beta.6 lib/compass/commands/registry.rb
compass-0.11.beta.5 lib/compass/commands/registry.rb
compass-0.11.beta.4 lib/compass/commands/registry.rb
compass-0.11.beta.3 lib/compass/commands/registry.rb
compass-0.11.beta.2 lib/compass/commands/registry.rb
compass-0.11.beta.1 lib/compass/commands/registry.rb
compass-0.11.beta.0 lib/compass/commands/registry.rb
compass-0.11.alpha.4 lib/compass/commands/registry.rb