Sha256: 5b71d6c8302716bda76c37719b497a95a6764d5456062fd5c45d355cc68382aa

Contents?: true

Size: 1.11 KB

Versions: 57

Compression:

Stored size: 1.11 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
      elsif matching.size > 1
        raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}"
      else
        raise Compass::Error, "Command not found: #{name}"
      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

57 entries across 56 versions & 6 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/compass-1.0.3/lib/compass/commands/registry.rb
compass-1.0.3 lib/compass/commands/registry.rb
compass-1.1.0.alpha.3 lib/compass/commands/registry.rb
compass-1.1.0.alpha.2 lib/compass/commands/registry.rb
compass-1.1.0.alpha.1 lib/compass/commands/registry.rb
compass-1.1.0.alpha.0 lib/compass/commands/registry.rb
compass-1.0.1 lib/compass/commands/registry.rb
compass-1.0.0 lib/compass/commands/registry.rb
compass-1.0.0.rc.1 lib/compass/commands/registry.rb
compass-1.0.0.rc.0 lib/compass/commands/registry.rb
compass-0.12.7 lib/compass/commands/registry.rb
compass-1.0.0.alpha.21 lib/compass/commands/registry.rb
compass-1.0.0.alpha.20 lib/compass/commands/registry.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/compass-0.12.3/lib/compass/commands/registry.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/compass-0.12.3/lib/compass/commands/registry.rb
compass-0.12.6 lib/compass/commands/registry.rb
compass-0.12.5 lib/compass/commands/registry.rb
compass-0.12.4 lib/compass/commands/registry.rb
compass-1.0.0.alpha.19 lib/compass/commands/registry.rb
compass-0.12.3 lib/compass/commands/registry.rb