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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 154ddd2d3a29b8ecc78ee38f814c6bbe729a5a6b
4
- data.tar.gz: 4b8aef184bd7704e2919a3d386d21e1cd588e4df
3
+ metadata.gz: 74158ffe7a45c37b1a0eaff36af21e2baf4dd9bd
4
+ data.tar.gz: 235219f3b1677ce37d5b8e9185f6fb7e2ca1a5d7
5
5
  SHA512:
6
- metadata.gz: 2402148318a7fbb6ffb553e816574043980f0bb8b0113cbb71260f678c371febf46cbe2635ac88fdccbbb9b717f73c8a3774609f66523aa07d37268a83eb2997
7
- data.tar.gz: 222955fe253831f03f4aeb6ed71062faa9a90facfd6e3ce06d15d94aa71239b952cb02dfe187a60de8b1899a769f39f88fc151948b769ff10159367c7cc5eac9
6
+ metadata.gz: 67743da902c72b95e462aae9d8669e718757b14d2174ea3ac1f1476434ed4af3cdb551ec1349d256204316ea643eb2214323377cfdd1a350944c696bdeb5ea5f
7
+ data.tar.gz: d04b7882d00e94389e4ab35fcee32e586962d7fbd67a5e5a2523dc6dd694ac26d151f8e5d998b8bd1aad26665271d28422c80817e36ea3d434d6c6751e5f0e1c
@@ -7,8 +7,8 @@ module EasyRepl
7
7
  "exit"
8
8
  end
9
9
 
10
- def self.run
11
- throw :exit_repl, :exit
10
+ def self.run(input)
11
+ throw :exit_inner_loop, :exit
12
12
  end
13
13
  end
14
14
  end
@@ -7,8 +7,8 @@ module EasyRepl
7
7
  "reload"
8
8
  end
9
9
 
10
- def self.run
11
- throw :exit_repl, :reload
10
+ def self.run(input)
11
+ throw :exit_inner_loop, :reload
12
12
  end
13
13
  end
14
14
  end
@@ -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
- exit_value = catch(:exit_repl) do
24
- loop do
23
+ exit_inner_loop_value = catch(:exit_inner_loop) do
24
+ loop do #inner loop
25
25
  begin
26
- before_input if respond_to? :before_input
27
- if block_given?
28
- yield EasyRepl.gets
29
- elsif respond_to? :process_input
30
- process_input(EasyRepl.gets)
31
- else
32
- puts EasyRepl.gets
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 exit_value == :exit
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 = "> "
@@ -1,3 +1,3 @@
1
1
  module EasyRepl
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
- EasyRepl.stub :prompt, seq do
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
- EasyRepl.stub :prompt, seq do
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
- EasyRepl.stub :prompt, seq do
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
- EasyRepl.stub :prompt, seq do
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
- EasyRepl.stub :prompt, seq do
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
- EasyRepl.stub :prompt, seq do
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler