# File lib/compass/commands/registry.rb, line 25 def abbreviation?(name) re = /^#{Regexp.escape(name)}/ @commands.keys.detect{|k| k.to_s =~ re} end
# File lib/compass/commands/registry.rb, line 12 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
# File lib/compass/commands/registry.rb, line 33 def all @commands.keys end
# File lib/compass/commands/registry.rb, line 29 def command_exists?(name) @commands ||= Hash.new name && (@commands.has_key?(name.to_sym) || abbreviation?(name)) end
# File lib/compass/commands/registry.rb, line 7 def get(name) return unless name @commands ||= Hash.new @commands[name.to_sym] || @commands[abbreviation_of(name)] end
# File lib/compass/commands/registry.rb, line 3 def register(name, command_class) @commands ||= Hash.new @commands[name.to_sym] = command_class end