Module: Compass::Commands::Registry
- Included in:
- Compass::Commands
- Defined in:
- lib/compass/commands/registry.rb
Instance Method Summary collapse
- #abbreviation?(name) ⇒ Boolean
- #abbreviation_of(name) ⇒ Object
- #all ⇒ Object
- #command_exists?(name) ⇒ Boolean
- #get(name) ⇒ Object (also: #[])
- #register(name, command_class) ⇒ Object (also: #[]=)
Instance Method Details
#abbreviation?(name) ⇒ Boolean
25 26 27 28 |
# File 'lib/compass/commands/registry.rb', line 25 def abbreviation?(name) re = /^#{Regexp.escape(name)}/ @commands.keys.detect{|k| k.to_s =~ re} end |
#abbreviation_of(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
#all ⇒ Object
33 34 35 |
# File 'lib/compass/commands/registry.rb', line 33 def all @commands.keys end |
#command_exists?(name) ⇒ Boolean
29 30 31 32 |
# 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 |
#get(name) ⇒ Object Also known as: []
7 8 9 10 11 |
# 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 |
#register(name, command_class) ⇒ Object Also known as: []=
3 4 5 6 |
# File 'lib/compass/commands/registry.rb', line 3 def register(name, command_class) @commands ||= Hash.new @commands[name.to_sym] = command_class end |