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.
- data/VERSION +1 -1
- data/lib/cinatra.rb +10 -12
- data/test/test_cinatra.rb +3 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
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
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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