interactive 0.4.0 → 0.5.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b4efce0bf189c7b0a8adc60366457b50510cbe1
|
4
|
+
data.tar.gz: 3e19e3f985a2b18722dc99ade99a3ef970feafa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6f3f4fc0e3b08451d43c5fa562999199ab2e890fcdb30fccf243da1269bf434abe8643936fcd01c34ba42ae6dab571be97945c5ca4f54e9811d6c781458094f
|
7
|
+
data.tar.gz: 50b82f8817f6706fae656063f65a66c1af98c2391c009552d351ca585eb369a8dd71c33d04335a62b7b43335f18c171011f9c40369557a1e45c3862f0a5113f1
|
data/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
v0.5.0 -- Fri Mar 20 20:01:26 EDT 2015
|
2
|
+
--------------------------------------
|
3
|
+
- added `Question#reask`.
|
4
|
+
|
1
5
|
v0.4.0 -- Thu Mar 19 08:32:20 EDT 2015
|
2
6
|
--------------------------------------
|
3
7
|
- added support for stubbing Question#ask RSpec's `instance_double` method.
|
data/README.md
CHANGED
@@ -154,6 +154,44 @@ Which path do you want to use? [0/1/c]
|
|
154
154
|
c -- cancel
|
155
155
|
```
|
156
156
|
|
157
|
+
### Question#reask
|
158
|
+
```ruby
|
159
|
+
|
160
|
+
require 'interactive'
|
161
|
+
include Interactive
|
162
|
+
|
163
|
+
outer_question = Question.new do |q|
|
164
|
+
q.question = "What do you want to do?"
|
165
|
+
q.options = [:eat, :sleep, :bathe]
|
166
|
+
end
|
167
|
+
|
168
|
+
inner_question = Question.new do |q|
|
169
|
+
q.question = "What do you want to eat?"
|
170
|
+
q.options = [:spaghetti, :mac_and_cheese, :back]
|
171
|
+
end
|
172
|
+
|
173
|
+
outer_question.ask do |outer_response|
|
174
|
+
if outer_response.eat?
|
175
|
+
inner_question.ask do |inner_response|
|
176
|
+
if inner_response.back?
|
177
|
+
outer_question.reask!
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
Assume we answer `e` and `b`, for `eat` and `back`:
|
185
|
+
|
186
|
+
```
|
187
|
+
What do you want to do? [e/s/b]
|
188
|
+
e
|
189
|
+
What do you want to eat? [s/m/b]
|
190
|
+
b
|
191
|
+
What do you want to do? [e/s/b]
|
192
|
+
...
|
193
|
+
```
|
194
|
+
|
157
195
|
## Development
|
158
196
|
|
159
197
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/interactive/question.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
class QuestionWithEagerFullExplanation < SimpleDelegator
|
2
2
|
def ask_and_wait_for_valid_response(&block)
|
3
3
|
loop do
|
4
|
+
@reask = false
|
4
5
|
puts "#{question} #{options.shortcuts_string}"
|
5
6
|
puts options.shortcuts_meanings
|
6
7
|
resp = Interactive::Response(options)
|
7
8
|
|
8
9
|
yield resp
|
9
|
-
break
|
10
|
+
break if !resp.invalid? && @reask == false
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
def reask!
|
15
|
+
@reask = true
|
16
|
+
end
|
12
17
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
class QuestionWithLazyFullExplanation < SimpleDelegator
|
2
2
|
def ask_and_wait_for_valid_response(&block)
|
3
3
|
loop do
|
4
|
+
@reask = false
|
4
5
|
puts "#{question} #{options.shortcuts_string}"
|
5
6
|
resp = Interactive::Response(options)
|
6
7
|
puts options.shortcuts_meanings if resp.invalid?
|
7
8
|
|
8
9
|
yield resp
|
9
|
-
break
|
10
|
+
break if !resp.invalid? && @reask == false
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
def reask!
|
15
|
+
@reask = true
|
16
|
+
end
|
12
17
|
end
|
data/lib/interactive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edderic Ugaddan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|