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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2703a01f7bc5d319b7c41edd4d8d3a56692afd46
4
- data.tar.gz: dd3c9fb388e87dfa20f58bbf513377fbc0f03d1c
3
+ metadata.gz: fa7fa580b2919ec587477758892ba2dcd9f0edee
4
+ data.tar.gz: 05400265239b2bd76e85f59b5ebf34700df15fcb
5
5
  SHA512:
6
- metadata.gz: cf6e415b42beef180b7f6f458e2060442c42a8e38b2081a28fe48a17b0d98f1db28e2a050b4c02f4328f66fe112f87ff525e8698a9489a722e28c8be03a1f1d0
7
- data.tar.gz: c9ab8b806ff243e3f6f7ef4624d6f0b7a597cbe41c2f49281f783b00124106ce2be67ca31152759268154ead51fb3f9008ba1e35fec4776163d9a805ba6736f0
6
+ metadata.gz: 47f23a9a9d8d4c28cdb752f9d2ad854310ed2212a4e9a1792038f13b271192bbb2f31faaf81f459b5dedb1a850ef37785247f849fa930cff26c2429c05c57634
7
+ data.tar.gz: a8db81aebdeac9512fb7f4326bfeb3345c28c75ed0e6168175e654bfbfad0058b51a42b0b514d9eb0d5b3f4d1ef2d80aaf276d78adf0509b47550c94ca6286b8
@@ -0,0 +1,11 @@
1
+ item do
2
+ expected do
3
+ static
4
+ set 'green'
5
+ end
6
+
7
+ actual do
8
+ gemnasium
9
+ slug 'akerl/userinput'
10
+ end
11
+ end
@@ -1,3 +1,7 @@
1
+ # 1.0.1 / 2016-02-13
2
+
3
+ * [FEATURE] Support setting custom IO object as file descriptor for output
4
+
1
5
  # 1.0.0 / 2015-01-19
2
6
 
3
7
  * [ENHANCEMENT] Stabilized API
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
- [![Code Climate](https://img.shields.io/codeclimate/github/akerl/userinput.svg)](https://codeclimate.com/github/akerl/userinput)
7
- [![Coverage Status](https://img.shields.io/coveralls/akerl/userinput.svg)](https://coveralls.io/r/akerl/userinput)
8
- [![Build Status](https://img.shields.io/travis/akerl/userinput.svg)](https://travis-ci.org/akerl/userinput)
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
@@ -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'
@@ -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
- fail "Supported validation type not provided #{@validation.class}"
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
- fail ArgumentError, 'No valid input provided' if @attempts == 0
73
+ raise ArgumentError, 'No valid input provided' if @attempts == 0
73
74
  end
74
75
 
75
76
  ##
@@ -1,9 +1,10 @@
1
- require 'simplecov'
2
- require 'coveralls'
3
-
4
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
- SimpleCov.start do
6
- add_filter '/spec/'
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'
@@ -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(subject).to receive(:print).with('_msg? [_default] ')
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(subject).to receive(:print).with('_msg? [_default] ')
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(prompt).to receive(:print).with('_msg? ').twice
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(prompt).to receive(:print).with('? ').twice
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(prompt).to receive(:print).with('? ')
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(prompt).to receive(:print).with('? ').twice
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(prompt).to receive(:print).with('? ')
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'userinput'
3
- s.version = '1.0.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.28.0'
17
- s.add_development_dependency 'rake', '~> 10.4.0'
18
- s.add_development_dependency 'coveralls', '~> 0.7.1'
19
- s.add_development_dependency 'rspec', '~> 3.1.0'
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.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: 2015-01-20 00:00:00.000000000 Z
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.28.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.28.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.4.0
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.4.0
40
+ version: 10.5.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: coveralls
42
+ name: codecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.7.1
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.7.1
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.1.0
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.1.0
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.4.5
123
+ rubygems_version: 2.5.1
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Simple user input library
@@ -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