easy_repl 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/easy_repl/commands/exit.rb +2 -2
- data/lib/easy_repl/commands/reload.rb +2 -2
- data/lib/easy_repl/repl.rb +16 -14
- data/lib/easy_repl/version.rb +1 -1
- data/test/easy_repl_test.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74158ffe7a45c37b1a0eaff36af21e2baf4dd9bd
|
4
|
+
data.tar.gz: 235219f3b1677ce37d5b8e9185f6fb7e2ca1a5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67743da902c72b95e462aae9d8669e718757b14d2174ea3ac1f1476434ed4af3cdb551ec1349d256204316ea643eb2214323377cfdd1a350944c696bdeb5ea5f
|
7
|
+
data.tar.gz: d04b7882d00e94389e4ab35fcee32e586962d7fbd67a5e5a2523dc6dd694ac26d151f8e5d998b8bd1aad26665271d28422c80817e36ea3d434d6c6751e5f0e1c
|
data/lib/easy_repl/repl.rb
CHANGED
@@ -17,26 +17,28 @@ module EasyRepl
|
|
17
17
|
module Repl
|
18
18
|
def start
|
19
19
|
IRB::HistorySavingAbility.extend(IRB::HistorySavingAbility) unless IRB::HistorySavingAbility === IRB::HistorySavingAbility
|
20
|
-
loop do
|
20
|
+
loop do #outer loop
|
21
21
|
setup if respond_to? :setup
|
22
22
|
begin
|
23
|
-
|
24
|
-
loop do
|
23
|
+
exit_inner_loop_value = catch(:exit_inner_loop) do
|
24
|
+
loop do #inner loop
|
25
25
|
begin
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
process_input
|
31
|
-
|
32
|
-
|
26
|
+
catch(:skip_process_input) do
|
27
|
+
before_input if respond_to? :before_input
|
28
|
+
if block_given?
|
29
|
+
yield self.gets
|
30
|
+
elsif respond_to? :process_input
|
31
|
+
process_input(self.gets)
|
32
|
+
else
|
33
|
+
puts self.gets
|
34
|
+
end
|
33
35
|
end
|
34
36
|
ensure
|
35
37
|
after_input if respond_to? :after_input
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
return if
|
41
|
+
return if exit_inner_loop_value == :exit
|
40
42
|
ensure
|
41
43
|
teardown if respond_to? :teardown
|
42
44
|
end
|
@@ -48,19 +50,19 @@ module EasyRepl
|
|
48
50
|
def gets
|
49
51
|
input = prompt.gets
|
50
52
|
command = commands.find {|c| c.matches(input)}
|
53
|
+
|
51
54
|
if command
|
52
|
-
command.run
|
53
|
-
return ""
|
55
|
+
return command.run(input)
|
54
56
|
else
|
55
57
|
return input
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
|
-
private
|
60
61
|
def commands
|
61
62
|
@commands ||= [EasyRepl::Commands::Exit, EasyRepl::Commands::Reload]
|
62
63
|
end
|
63
64
|
|
65
|
+
private
|
64
66
|
def prompt
|
65
67
|
@io ||= IRB::ReadlineInputMethod.new.tap do |new_io|
|
66
68
|
new_io.prompt = "> "
|
data/lib/easy_repl/version.rb
CHANGED
data/test/easy_repl_test.rb
CHANGED
@@ -54,7 +54,7 @@ describe EasyRepl do
|
|
54
54
|
it "calls setup before asking for input" do
|
55
55
|
out = ''
|
56
56
|
seq = Support::CommandSequence.new "exit"
|
57
|
-
|
57
|
+
Support::SetupEasyRepl.stub :prompt, seq do
|
58
58
|
out, err = capture_io do
|
59
59
|
Support::SetupEasyRepl.start
|
60
60
|
end
|
@@ -65,7 +65,7 @@ describe EasyRepl do
|
|
65
65
|
it "calls setup when the reload command is entered" do
|
66
66
|
out = ''
|
67
67
|
seq = Support::CommandSequence.new "reload", "exit"
|
68
|
-
|
68
|
+
Support::SetupEasyRepl.stub :prompt, seq do
|
69
69
|
out, err = capture_io do
|
70
70
|
Support::SetupEasyRepl.start
|
71
71
|
end
|
@@ -78,7 +78,7 @@ describe EasyRepl do
|
|
78
78
|
it "calls teardown before exiting" do
|
79
79
|
out = ''
|
80
80
|
seq = Support::CommandSequence.new "exit"
|
81
|
-
|
81
|
+
Support::TeardownEasyRepl.stub :prompt, seq do
|
82
82
|
out, err = capture_io do
|
83
83
|
Support::TeardownEasyRepl.start
|
84
84
|
end
|
@@ -89,7 +89,7 @@ describe EasyRepl do
|
|
89
89
|
it "calls teardown when the reload command is entered" do
|
90
90
|
out = ''
|
91
91
|
seq = Support::CommandSequence.new "reload", "exit"
|
92
|
-
|
92
|
+
Support::TeardownEasyRepl.stub :prompt, seq do
|
93
93
|
out, err = capture_io do
|
94
94
|
Support::TeardownEasyRepl.start
|
95
95
|
end
|
@@ -102,7 +102,7 @@ describe EasyRepl do
|
|
102
102
|
it "calls before input before every command" do
|
103
103
|
out = ''
|
104
104
|
seq = Support::CommandSequence.new "XXX", "exit"
|
105
|
-
|
105
|
+
Support::BeforeInputEasyRepl.stub :prompt, seq do
|
106
106
|
out, err = capture_io do
|
107
107
|
Support::BeforeInputEasyRepl.start
|
108
108
|
end
|
@@ -115,7 +115,7 @@ describe EasyRepl do
|
|
115
115
|
it "calls after input after every command" do
|
116
116
|
out = ''
|
117
117
|
seq = Support::CommandSequence.new "XXX", "exit"
|
118
|
-
|
118
|
+
Support::AfterInputEasyRepl.stub :prompt, seq do
|
119
119
|
out, err = capture_io do
|
120
120
|
Support::AfterInputEasyRepl.start
|
121
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Erin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|