Module: Compass::Commands::Registry
- Included in:
- Compass::Commands
- Defined in:
- lib/compass/commands/registry.rb
Instance Method Summary (collapse)
- - (Boolean) abbreviation?(name)
- - (Object) abbreviation_of(name)
- - (Object) all
- - (Boolean) command_exists?(name)
- - (Object) get(name) (also: #[])
- - (Object) register(name, command_class) (also: #[]=)
Instance Method Details
- (Boolean) abbreviation?(name)
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 |
- (Object) abbreviation_of(name)
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 |
- (Object) all
33 34 35 |
# File 'lib/compass/commands/registry.rb', line 33 def all @commands.keys end |
- (Boolean) command_exists?(name)
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 |
- (Object) get(name) 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 |
- (Object) register(name, command_class) 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 |