Permalink
Browse files

set identifier for Command

  • Loading branch information...
1 parent 530315c commit c3c7189767e89de1fb84acf3a8a2811080b63c3a @Oshuma committed Mar 17, 2010
Showing with 14 additions and 1 deletion.
  1. +3 −1 lib/alfred/command.rb
  2. +11 −0 spec/alfred/command_spec.rb
View
4 lib/alfred/command.rb
@@ -46,12 +46,14 @@ def initialize(*args)
options = args.first
@name = options[:name] || options['name']
@raw = options[:exec] || options['exec']
+ @id = options[:id] || options['id']
else
@name = args[0]
@raw = args[1]
+ @id = args[2]
end
raise Alfred::CommandError unless @name && @raw
- generate_id
+ generate_id unless @id
end
def exec!
View
11 spec/alfred/command_spec.rb
@@ -73,6 +73,17 @@
command = Command.new({ :name => 'The Command', :exec => 'hostname' })
command.id.should == 'the_command'
end
+
+ it 'uses a custom id (hash constructor)' do
+ @options[:id] = 'the_command'
+ command = Command.new(@options)
+ command.id.should == 'the_command'
+ end
+
+ it 'uses a custom id (array constructor)' do
+ command = Command.new('Name', 'hostname', 'the_command')
+ command.id.should == 'the_command'
+ end
end # instance
end

0 comments on commit c3c7189

Please sign in to comment.