interact 0.1 → 0.2
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/README.md +6 -3
- data/lib/interact.rb +22 -8
- data/lib/version.rb +1 -1
- metadata +5 -7
data/README.md
CHANGED
@@ -80,17 +80,20 @@ if they rewind.
|
|
80
80
|
|
81
81
|
## Disabling Rewinding
|
82
82
|
|
83
|
-
Interact provides a nifty user-friendly "rewinding" feature, which allows the
|
83
|
+
Interact provides a nifty user-friendly "rewinding" feature, which allows the
|
84
|
+
user to go back in time and re-answer a question. If you don't want this
|
85
|
+
feature, simply call `disable_rewind` in your class. You can re-enable it with
|
86
|
+
`enable_rewind` in subclasses.
|
84
87
|
|
85
88
|
```ruby
|
86
89
|
class NoRewind
|
87
90
|
include Interactive
|
88
|
-
|
91
|
+
disable_rewind
|
89
92
|
|
90
93
|
def run
|
91
94
|
res = ask "Is there no return?", :default => true
|
92
95
|
|
93
|
-
if res ==
|
96
|
+
if res == rewind_enabled?
|
94
97
|
puts "You're right!"
|
95
98
|
else
|
96
99
|
puts "Nope! It's disabled."
|
data/lib/interact.rb
CHANGED
@@ -328,16 +328,30 @@ module Interact
|
|
328
328
|
end
|
329
329
|
|
330
330
|
module Interactive
|
331
|
-
# Allow classes to disable the rewind feature via
|
332
|
-
#
|
331
|
+
# Allow classes to enable/disable the rewind feature via +disable_rewind+
|
332
|
+
# and +enable_rewind+.
|
333
333
|
def self.included klass
|
334
|
-
|
334
|
+
class << klass
|
335
|
+
def disable_rewind
|
336
|
+
def self.rewind_enabled?
|
337
|
+
false
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def enable_rewind
|
342
|
+
def self.rewind_enabled?
|
343
|
+
true
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def rewind_enabled?
|
348
|
+
true
|
349
|
+
end
|
350
|
+
end
|
335
351
|
|
336
352
|
klass.class_eval do
|
337
|
-
|
338
|
-
|
339
|
-
def allow_rewind
|
340
|
-
self.class.send :class_variable_get, :@@allow_rewind
|
353
|
+
def rewind_enabled?
|
354
|
+
self.class.rewind_enabled?
|
341
355
|
end
|
342
356
|
end
|
343
357
|
end
|
@@ -385,7 +399,7 @@ module Interactive
|
|
385
399
|
# The block should return the updated +position+, or +nil+ if it didn't
|
386
400
|
# handle the event
|
387
401
|
def ask(question, options = {})
|
388
|
-
rewind = Interact::HAS_CALLCC &&
|
402
|
+
rewind = Interact::HAS_CALLCC && rewind_enabled?
|
389
403
|
|
390
404
|
if rewind
|
391
405
|
prompt, answer = callcc { |cc| [cc, nil] }
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alex Suraci
|
@@ -14,8 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-10-
|
18
|
-
default_executable:
|
17
|
+
date: 2011-10-26 00:00:00 Z
|
19
18
|
dependencies:
|
20
19
|
- !ruby/object:Gem::Dependency
|
21
20
|
name: rake
|
@@ -61,7 +60,6 @@ files:
|
|
61
60
|
- Rakefile
|
62
61
|
- lib/interact.rb
|
63
62
|
- lib/version.rb
|
64
|
-
has_rdoc: true
|
65
63
|
homepage: http://github.com/vito/interact
|
66
64
|
licenses: []
|
67
65
|
|
@@ -91,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
89
|
requirements: []
|
92
90
|
|
93
91
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.6
|
92
|
+
rubygems_version: 1.8.6
|
95
93
|
signing_key:
|
96
94
|
specification_version: 3
|
97
95
|
summary: A simple API for command-line interaction.
|