Sha256: 9d4cf012f159b34db081b37dd6d7527d545aad943b727d3f019dc924807140ef
Contents?: true
Size: 983 Bytes
Versions: 17
Compression:
Stored size: 983 Bytes
Contents
module Compass::Commands module Registry def register(name, command_class) @commands ||= Hash.new @commands[name.to_sym] = command_class end def get(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 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
17 entries across 17 versions & 1 rubygems