userinput 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.prospectus +11 -0
- data/CHANGELOG.md +4 -0
- data/README.md +15 -3
- data/circle.yml +12 -0
- data/lib/userinput.rb +5 -4
- data/spec/spec_helper.rb +7 -6
- data/spec/userinput_spec.rb +15 -7
- data/userinput.gemspec +5 -5
- metadata +14 -13
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7fa580b2919ec587477758892ba2dcd9f0edee
|
4
|
+
data.tar.gz: 05400265239b2bd76e85f59b5ebf34700df15fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f23a9a9d8d4c28cdb752f9d2ad854310ed2212a4e9a1792038f13b271192bbb2f31faaf81f459b5dedb1a850ef37785247f849fa930cff26c2429c05c57634
|
7
|
+
data.tar.gz: a8db81aebdeac9512fb7f4326bfeb3345c28c75ed0e6168175e654bfbfad0058b51a42b0b514d9eb0d5b3f4d1ef2d80aaf276d78adf0509b47550c94ca6286b8
|
data/.prospectus
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,9 @@ userinput
|
|
3
3
|
|
4
4
|
[![Gem Version](https://img.shields.io/gem/v/userinput.svg)](https://rubygems.org/gems/userinput)
|
5
5
|
[![Dependency Status](https://img.shields.io/gemnasium/akerl/userinput.svg)](https://gemnasium.com/akerl/userinput)
|
6
|
-
[![
|
7
|
-
[![Coverage Status](https://img.shields.io/
|
8
|
-
[![
|
6
|
+
[![Build Status](https://img.shields.io/circleci/project/akerl/userinput.svg)](https://circleci.com/gh/akerl/userinput)
|
7
|
+
[![Coverage Status](https://img.shields.io/codecov/c/github/akerl/userinput.svg)](https://codecov.io/github/akerl/userinput)
|
8
|
+
[![Code Quality](https://img.shields.io/codacy/fbda4046154e4ac38a47f2c6627d57c8.svg)](https://www.codacy.com/app/akerl/userinput)
|
9
9
|
[![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
|
10
10
|
|
11
11
|
A simple user input library
|
@@ -85,6 +85,18 @@ Password?
|
|
85
85
|
=> "_password"
|
86
86
|
```
|
87
87
|
|
88
|
+
Setting the file descriptor lets you control where output is sent (for instance, use this to print messages on STDERR or to a custom IO object):
|
89
|
+
|
90
|
+
```
|
91
|
+
> require 'userinput'
|
92
|
+
=> true
|
93
|
+
> prompt = UserInput.new(message: 'Password', secret: true, fd: STDERR)
|
94
|
+
=> #<UserInput::Prompt:0x007f888110a138 @attempts=nil, @message="Password", @default=nil, @secret=true, @fd=#<IO:<STDERR>>, @validation=nil>
|
95
|
+
> prompt.ask
|
96
|
+
Password?
|
97
|
+
=> "_password"
|
98
|
+
```
|
99
|
+
|
88
100
|
## Installation
|
89
101
|
|
90
102
|
gem install userinput
|
data/circle.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
dependencies:
|
2
|
+
override:
|
3
|
+
- 'rvm-exec 1.9.3-p551 bundle install'
|
4
|
+
- 'rvm-exec 2.0.0-p645 bundle install'
|
5
|
+
- 'rvm-exec 2.1.6 bundle install'
|
6
|
+
- 'rvm-exec 2.2.2 bundle install'
|
7
|
+
test:
|
8
|
+
override:
|
9
|
+
- 'rvm-exec 1.9.3-p551 bundle exec rake'
|
10
|
+
- 'rvm-exec 2.0.0-p645 bundle exec rake'
|
11
|
+
- 'rvm-exec 2.1.6 bundle exec rake'
|
12
|
+
- 'rvm-exec 2.2.2 bundle exec rake'
|
data/lib/userinput.rb
CHANGED
@@ -20,13 +20,14 @@ module UserInput
|
|
20
20
|
@message = params[:message] || ''
|
21
21
|
@default = params[:default]
|
22
22
|
@secret = params[:secret] || false
|
23
|
+
@fd = params[:fd] || STDOUT
|
23
24
|
@validation = block || params[:validation]
|
24
25
|
end
|
25
26
|
|
26
27
|
##
|
27
28
|
# Request user input
|
28
29
|
def ask
|
29
|
-
print "#{@message}? #{@default.nil? ? '' : "[#{@default}] "}"
|
30
|
+
@fd.print "#{@message}? #{@default.nil? ? '' : "[#{@default}] "}"
|
30
31
|
disable_echo if @secret
|
31
32
|
|
32
33
|
input = _ask
|
@@ -51,7 +52,7 @@ module UserInput
|
|
51
52
|
when NilClass
|
52
53
|
return true
|
53
54
|
else
|
54
|
-
|
55
|
+
raise "Supported validation type not provided #{@validation.class}"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
@@ -60,7 +61,7 @@ module UserInput
|
|
60
61
|
def _ask
|
61
62
|
input = STDIN.gets.chomp
|
62
63
|
input = @default if input.empty? && @default
|
63
|
-
puts if @secret
|
64
|
+
@fd.puts if @secret
|
64
65
|
input
|
65
66
|
end
|
66
67
|
|
@@ -69,7 +70,7 @@ module UserInput
|
|
69
70
|
def check_counter
|
70
71
|
return if @attempts.nil?
|
71
72
|
@attempts -= 1
|
72
|
-
|
73
|
+
raise ArgumentError, 'No valid input provided' if @attempts == 0
|
73
74
|
end
|
74
75
|
|
75
76
|
##
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
SimpleCov.formatter =
|
5
|
-
SimpleCov.start do
|
6
|
-
|
1
|
+
if ENV['CI'] == 'true'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'codecov'
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/spec/'
|
7
|
+
end
|
7
8
|
end
|
8
9
|
|
9
10
|
require 'rspec'
|
data/spec/userinput_spec.rb
CHANGED
@@ -25,13 +25,13 @@ describe UserInput do
|
|
25
25
|
describe '#ask' do
|
26
26
|
it 'prompts for user input' do
|
27
27
|
allow(STDIN).to receive(:gets) { "_answer\n" }
|
28
|
-
expect(
|
28
|
+
expect(STDOUT).to receive(:print).with('_msg? [_default] ')
|
29
29
|
expect(subject.ask).to eql '_answer'
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns the default if available' do
|
33
33
|
allow(STDIN).to receive(:gets) { "\n" }
|
34
|
-
expect(
|
34
|
+
expect(STDOUT).to receive(:print).with('_msg? [_default] ')
|
35
35
|
expect(subject.ask).to eql '_default'
|
36
36
|
end
|
37
37
|
|
@@ -42,7 +42,7 @@ describe UserInput do
|
|
42
42
|
validation: /[0-9]+/
|
43
43
|
)
|
44
44
|
allow(STDIN).to receive(:gets).and_return("_str\n", "29\n")
|
45
|
-
expect(
|
45
|
+
expect(STDOUT).to receive(:print).with('_msg? ').twice
|
46
46
|
expect(prompt.ask).to eql '29'
|
47
47
|
end
|
48
48
|
end
|
@@ -50,7 +50,7 @@ describe UserInput do
|
|
50
50
|
it 'validates input' do
|
51
51
|
prompt = UserInput::Prompt.new { |x| x == 'correct' }
|
52
52
|
allow(STDIN).to receive(:gets).and_return("_str\n", "correct\n")
|
53
|
-
expect(
|
53
|
+
expect(STDOUT).to receive(:print).with('? ').twice
|
54
54
|
expect(prompt.ask).to eql 'correct'
|
55
55
|
end
|
56
56
|
end
|
@@ -58,7 +58,7 @@ describe UserInput do
|
|
58
58
|
it 'raises a RuntimeError' do
|
59
59
|
prompt = UserInput::Prompt.new(validation: 28)
|
60
60
|
allow(STDIN).to receive(:gets).and_return("_str\n")
|
61
|
-
expect(
|
61
|
+
expect(STDOUT).to receive(:print).with('? ')
|
62
62
|
expect { prompt.ask }.to raise_error RuntimeError
|
63
63
|
end
|
64
64
|
end
|
@@ -66,7 +66,7 @@ describe UserInput do
|
|
66
66
|
it 'raises an error if max attempts is reached' do
|
67
67
|
prompt = UserInput::Prompt.new(attempts: 2) { false }
|
68
68
|
allow(STDIN).to receive(:gets).and_return("_str\n", "_foo\n")
|
69
|
-
expect(
|
69
|
+
expect(STDOUT).to receive(:print).with('? ').twice
|
70
70
|
expect { prompt.ask }.to raise_error ArgumentError
|
71
71
|
end
|
72
72
|
end
|
@@ -74,7 +74,15 @@ describe UserInput do
|
|
74
74
|
it 'disables echo for secret input' do
|
75
75
|
prompt = UserInput::Prompt.new(secret: true)
|
76
76
|
allow(STDIN).to receive(:gets).and_return("_str\n")
|
77
|
-
expect(
|
77
|
+
expect(STDOUT).to receive(:print).with('? ')
|
78
|
+
expect(prompt.ask).to eql '_str'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'accepts an alternate file descriptor for output' do
|
82
|
+
target = StringIO.new
|
83
|
+
prompt = UserInput::Prompt.new(fd: target)
|
84
|
+
allow(STDIN).to receive(:gets).and_return("_str\n")
|
85
|
+
expect(target).to receive(:print).with('? ')
|
78
86
|
expect(prompt.ask).to eql '_str'
|
79
87
|
end
|
80
88
|
end
|
data/userinput.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'userinput'
|
3
|
-
s.version = '1.0.
|
3
|
+
s.version = '1.0.1'
|
4
4
|
s.date = Time.now.strftime("%Y-%m-%d")
|
5
5
|
|
6
6
|
s.summary = 'Simple user input library'
|
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.files = `git ls-files`.split
|
14
14
|
s.test_files = `git ls-files spec/*`.split
|
15
15
|
|
16
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
17
|
-
s.add_development_dependency 'rake', '~> 10.
|
18
|
-
s.add_development_dependency '
|
19
|
-
s.add_development_dependency 'rspec', '~> 3.
|
16
|
+
s.add_development_dependency 'rubocop', '~> 0.37.0'
|
17
|
+
s.add_development_dependency 'rake', '~> 10.5.0'
|
18
|
+
s.add_development_dependency 'codecov', '~> 0.1.1'
|
19
|
+
s.add_development_dependency 'rspec', '~> 3.4.0'
|
20
20
|
s.add_development_dependency 'fuubar', '~> 2.0.0'
|
21
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userinput
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.37.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.37.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 10.
|
33
|
+
version: 10.5.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 10.
|
40
|
+
version: 10.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: codecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.1.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.1.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.4.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fuubar
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +87,15 @@ extensions: []
|
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
89
|
- ".gitignore"
|
90
|
+
- ".prospectus"
|
90
91
|
- ".rspec"
|
91
92
|
- ".rubocop.yml"
|
92
|
-
- ".travis.yml"
|
93
93
|
- CHANGELOG.md
|
94
94
|
- Gemfile
|
95
95
|
- LICENSE
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
+
- circle.yml
|
98
99
|
- lib/userinput.rb
|
99
100
|
- spec/spec_helper.rb
|
100
101
|
- spec/userinput_spec.rb
|
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
version: '0'
|
120
121
|
requirements: []
|
121
122
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.5.1
|
123
124
|
signing_key:
|
124
125
|
specification_version: 4
|
125
126
|
summary: Simple user input library
|
data/.travis.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
rvm:
|
5
|
-
- 2.2.0
|
6
|
-
- 2.1.5
|
7
|
-
- 2.0.0-p598
|
8
|
-
- 1.9.3-p551
|
9
|
-
notifications:
|
10
|
-
email: false
|
11
|
-
irc:
|
12
|
-
template:
|
13
|
-
- '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
|
14
|
-
channels:
|
15
|
-
- irc.oftc.net#akerl
|