optser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -17
- data/.travis.yml +7 -0
- data/Guardfile +1 -2
- data/NOTICE.txt +1 -1
- data/README.md +10 -0
- data/lib/optser.rb +19 -2
- data/lib/optser/version.rb +1 -9
- data/optser.gemspec +1 -1
- data/spec/optser_spec.rb +38 -7
- metadata +5 -4
data/.gitignore
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
2
6
|
Gemfile.lock
|
3
|
-
|
4
|
-
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
5
9
|
coverage
|
6
|
-
|
7
|
-
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
8
13
|
rdoc
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# bundler config
|
15
|
-
.bundle
|
16
|
-
|
17
|
-
# bundler installs here if bundle path is set to "vendor"
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
18
|
vendor
|
19
|
-
|
20
|
-
# generated builds
|
21
|
-
pkg
|
data/.travis.yml
ADDED
data/Guardfile
CHANGED
data/NOTICE.txt
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,16 @@ Optser
|
|
3
3
|
|
4
4
|
Handle options from a set of arguments.
|
5
5
|
|
6
|
+
Optser Links
|
7
|
+
------------
|
8
|
+
|
9
|
+
* Source: https://github.com/byu/optser
|
10
|
+
* Continuous Integration: https://travis-ci.org/byu/optser
|
11
|
+
* [![Build Status](https://secure.travis-ci.org/byu/optser.png)](http://travis-ci.org/byu/optser)
|
12
|
+
* RubyGems: http://rubygems.org/gems/optser
|
13
|
+
* RubyDocs: http://rubydoc.info/gems/optser
|
14
|
+
|
15
|
+
|
6
16
|
Installation
|
7
17
|
============
|
8
18
|
|
data/lib/optser.rb
CHANGED
@@ -21,12 +21,29 @@ require 'optser/opt_set'
|
|
21
21
|
#
|
22
22
|
module Optser
|
23
23
|
|
24
|
+
##
|
25
|
+
# Parses the options from the arguments list, and creates a
|
26
|
+
# brand new OptSet instance to lookup the options; but does not
|
27
|
+
# modify the args.
|
28
|
+
#
|
29
|
+
def self.extract_options(args)
|
30
|
+
return parse_options(args.last.is_a?(::Hash) ? args.last : nil)
|
31
|
+
end
|
32
|
+
|
24
33
|
##
|
25
34
|
# Extracts the options from the arguments list, and creates a
|
26
|
-
# brand new OptSet instance to lookup the options
|
35
|
+
# brand new OptSet instance to lookup the options; pops the options
|
36
|
+
# off the args list if we have it.
|
27
37
|
#
|
28
38
|
def self.extract_options!(args)
|
29
|
-
return
|
39
|
+
return parse_options(args.last.is_a?(::Hash) ? args.pop : nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Creates a new OptSet from the given options.
|
44
|
+
#
|
45
|
+
def self.parse_options(options)
|
46
|
+
return Optser::OptSet.new options
|
30
47
|
end
|
31
48
|
|
32
49
|
end
|
data/lib/optser/version.rb
CHANGED
data/optser.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'optser/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'optser'
|
8
|
-
gem.version = Optser::
|
8
|
+
gem.version = Optser::VERSION
|
9
9
|
gem.authors = ['Benjamin Yu']
|
10
10
|
gem.email = ['benjaminlyu@gmail.com']
|
11
11
|
gem.description = 'Handle options from a set of arguments'
|
data/spec/optser_spec.rb
CHANGED
@@ -2,6 +2,25 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Optser do
|
4
4
|
|
5
|
+
describe '.extract_options' do
|
6
|
+
let(:given_options) {
|
7
|
+
FactoryGirl.create :random_options
|
8
|
+
}
|
9
|
+
let(:given_args) {
|
10
|
+
[ given_options ]
|
11
|
+
}
|
12
|
+
it 'returns an OptSet without popping off arguments' do
|
13
|
+
expect(given_args.size).to eq(1)
|
14
|
+
opt_set = described_class.extract_options given_args
|
15
|
+
expect(opt_set).to be_a_kind_of(Optser::OptSet)
|
16
|
+
expect(opt_set.get(:option_a)).to eq(given_options.option_a)
|
17
|
+
expect(opt_set.get(:option_b)).to eq(given_options.option_b)
|
18
|
+
expect(opt_set.get(:nonexist, 'DEFAULT')).to eq('DEFAULT')
|
19
|
+
# Make sure it didn't pop off the args list
|
20
|
+
expect(given_args.size).to eq(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
describe '.extract_options!' do
|
6
25
|
let(:given_options) {
|
7
26
|
FactoryGirl.create :random_options
|
@@ -9,33 +28,45 @@ describe Optser do
|
|
9
28
|
|
10
29
|
it 'returns an OptSet' do
|
11
30
|
opt_set = described_class.extract_options! []
|
12
|
-
opt_set.
|
31
|
+
expect(opt_set).to be_a_kind_of(Optser::OptSet)
|
13
32
|
end
|
14
33
|
|
15
34
|
it 'returns an OptSet with our option set' do
|
16
35
|
opt_set = described_class.extract_options! [
|
17
36
|
given_options
|
18
37
|
]
|
19
|
-
opt_set.
|
20
|
-
opt_set.get(:option_a).
|
21
|
-
opt_set.get(:option_b).
|
22
|
-
opt_set.get(:nonexist, 'DEFAULT').
|
38
|
+
expect(opt_set).to be_a_kind_of(Optser::OptSet)
|
39
|
+
expect(opt_set.get(:option_a)).to eq(given_options.option_a)
|
40
|
+
expect(opt_set.get(:option_b)).to eq(given_options.option_b)
|
41
|
+
expect(opt_set.get(:nonexist, 'DEFAULT')).to eq('DEFAULT')
|
23
42
|
end
|
24
43
|
|
25
44
|
it 'pops off the options hash' do
|
26
45
|
arguments = [1, 2, 3, 4, given_options]
|
27
46
|
original_size = arguments.size
|
28
47
|
described_class.extract_options! arguments
|
29
|
-
arguments.size.
|
48
|
+
expect(arguments.size).to eq(original_size - 1)
|
30
49
|
end
|
31
50
|
|
32
51
|
it 'does not modify arguments w/o a trailing hash' do
|
33
52
|
arguments = [1, 2, 3, 4].freeze
|
34
53
|
original_size = arguments.size
|
35
54
|
described_class.extract_options! arguments
|
36
|
-
arguments.size.
|
55
|
+
expect(arguments.size).to eq(original_size)
|
37
56
|
end
|
57
|
+
end
|
38
58
|
|
59
|
+
describe '.parse_options' do
|
60
|
+
let(:given_options) {
|
61
|
+
FactoryGirl.create :random_options
|
62
|
+
}
|
63
|
+
it 'returns an OptSet w/ options' do
|
64
|
+
opt_set = described_class.parse_options given_options
|
65
|
+
expect(opt_set).to be_a_kind_of(Optser::OptSet)
|
66
|
+
expect(opt_set.get(:option_a)).to eq(given_options.option_a)
|
67
|
+
expect(opt_set.get(:option_b)).to eq(given_options.option_b)
|
68
|
+
expect(opt_set.get(:nonexist, 'DEFAULT')).to eq('DEFAULT')
|
69
|
+
end
|
39
70
|
end
|
40
71
|
|
41
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -35,6 +35,7 @@ extensions: []
|
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
|
+
- .travis.yml
|
38
39
|
- Gemfile
|
39
40
|
- Guardfile
|
40
41
|
- LICENSE.txt
|
@@ -64,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
65
|
version: '0'
|
65
66
|
segments:
|
66
67
|
- 0
|
67
|
-
hash: -
|
68
|
+
hash: -951095661251092663
|
68
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
70
|
none: false
|
70
71
|
requirements:
|
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
74
|
version: '0'
|
74
75
|
segments:
|
75
76
|
- 0
|
76
|
-
hash: -
|
77
|
+
hash: -951095661251092663
|
77
78
|
requirements: []
|
78
79
|
rubyforge_project:
|
79
80
|
rubygems_version: 1.8.23
|