cinatra 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/cinatra.rb +10 -12
  3. data/test/test_cinatra.rb +3 -0
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/cinatra.rb CHANGED
@@ -5,7 +5,7 @@ class Cinatra
5
5
  include Singleton
6
6
 
7
7
  def add_command(name, &block)
8
- raise ArgumentError, "invalid command name: #{name}." unless name.to_s =~ /^\w+$/
8
+ raise ArgumentError, "invalid command name: #{name}." unless /^\w+$/ =~ name.to_s
9
9
  raise "command '#{name}' is already exists." if commands.key?(name.to_sym)
10
10
 
11
11
  commands[name.to_sym] = block
@@ -24,16 +24,14 @@ class Cinatra
24
24
  end
25
25
 
26
26
  def call(line)
27
- if /^\s*(\w+)\s+(.*?)\s*$/ =~ line
28
- command = commands[$1.to_sym]
29
- unless command
30
- puts "Command not found!"
31
- else
32
- begin
33
- command.call($2)
34
- rescue Exception => e
35
- puts e.message
36
- end
27
+ return unless /^\s*(\w+)\s+(.*?)\s*$/ =~ line
28
+ unless command = commands[$1.to_sym]
29
+ puts "Command `#{command}` not found!"
30
+ else
31
+ begin
32
+ command.call($2)
33
+ rescue Exception => e
34
+ puts e.message
37
35
  end
38
36
  end
39
37
  end
@@ -50,7 +48,7 @@ class Cinatra
50
48
 
51
49
  Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
52
50
  Readline.completion_proc = lambda do |text|
53
- Cinatra.commands.keys.map{|i| i.to_s}.grep(/#{Regexp.quote(text)}/)
51
+ Cinatra.commands.keys.map {|i| i.to_s }.grep(/#{Regexp.quote(text)}/)
54
52
  end
55
53
 
56
54
  while buf = Readline.readline('> ', true)
data/test/test_cinatra.rb CHANGED
@@ -42,7 +42,10 @@ class TestCinatra < Test::Unit::TestCase
42
42
 
43
43
  should "not call the command" do
44
44
  mock(@block).call('foo bar').times(0)
45
+
46
+ $stdout = StringIO.new
45
47
  Cinatra.call(' test_ foo bar ')
48
+ $stdout = STDOUT
46
49
  end
47
50
  end
48
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo