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: fc90b251376282f7c2fbab5ef3fc94ad4547ecf3
4
- data.tar.gz: c8b1d933341201dbb9edeb0caf733b436f933ba9
3
+ metadata.gz: 9b4efce0bf189c7b0a8adc60366457b50510cbe1
4
+ data.tar.gz: 3e19e3f985a2b18722dc99ade99a3ef970feafa2
5
5
  SHA512:
6
- metadata.gz: 8c7d6275910d2e2946bd744a3a2318b548818b4c086801a1e97eba37766dd667254dc86cd498f60f8817aba8301120cb7ddaa3f72b478573fec66e554e24703f
7
- data.tar.gz: 8d98bb7e1f87b0f8bb4d52e96f307bfe1ca57528e55046ebbeb80330c0f8bdbdb26250a5770b16b793a9a811aa47d5c37a6b8481b47550946c3a02f5c8686acf
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.
@@ -1,6 +1,10 @@
1
+ require 'forwardable'
2
+
1
3
  module Interactive
2
4
  class Question
5
+ extend Forwardable
3
6
  attr_accessor :question, :options
7
+ def_delegators :@question_type, :reask!
4
8
 
5
9
  def initialize(&block)
6
10
  yield self
@@ -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 unless resp.invalid?
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 unless resp.invalid?
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,3 +1,3 @@
1
1
  module Interactive
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.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-19 00:00:00.000000000 Z
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake