optioning 0.0.2 → 0.0.3

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: 94cb481fb510629a1b80e3045cd30d438e39948a
4
- data.tar.gz: 547c8ac83c7adc704f8899c747623df3a8798e2d
3
+ metadata.gz: cb571b317a86bb694b31fe6855625a4ba1c09b60
4
+ data.tar.gz: 1ed0d7f6e2b6f00408cb822c9646cafa7a380289
5
5
  SHA512:
6
- metadata.gz: 52b86fd8b12200166e1c83993f6000067a81e09be858da34b9ffe01d92565dc2d9855996ab4375206118c6dfa71353b697c1ff802834bc612583206dcafa94a6
7
- data.tar.gz: 0e0ea2c55acac9a4f06568d4e20f89afe395c49321d442969e61fcdf334c049d21c36ebb9db52db16e2d74658a7702700926df9b8e1e65b5561d4c4c5415696e
6
+ metadata.gz: 779901e1f14d001f9b8bb86ad71ff0220a0e828314a56f203dd111f41ff73cf87bd49a904114fc218863749ccfa6519a8b811bfeb74147f0ceb60ec09b33ee21
7
+ data.tar.gz: 7d38b65431ad13a11ce86ab25bdb973e6d7549bd2ecfc6e99a026235dc35b5e3b59544a0593e0adf497035f6baa64dee630f4a81486f2289e575401e6265c30b
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.0.3 2014-05-13
2
+
3
+ ## first public release :heartpulse:
@@ -1,3 +1,3 @@
1
1
  class Optioning
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/optioning.rb CHANGED
@@ -19,7 +19,7 @@ class Optioning
19
19
  def initialize(args)
20
20
  @args = args
21
21
  @values = @args.dup
22
- @options = @values.pop if @args.last.is_a? Hash
22
+ @options = @values.pop.dup if @args.last.is_a? Hash
23
23
  end
24
24
 
25
25
  # Return the value for a specific option
@@ -33,7 +33,7 @@ class Optioning
33
33
  # @return value for option passed as parameter
34
34
  def on(option)
35
35
  replace_deprecations
36
- @options[option]
36
+ options.fetch option, nil
37
37
  end
38
38
 
39
39
  # Creates a deprecation for an option, stores info about it's replacement
@@ -90,7 +90,7 @@ class Optioning
90
90
  unrecognized_options.each do |unrecognized|
91
91
  $stderr.write "NOTE: unrecognized option `:#{unrecognized}` used.\n"
92
92
  end
93
- recognized_options_warn called_from
93
+ recognized_options_warn(called_from) if unrecognized_options.count > 0
94
94
  self
95
95
  end
96
96
 
@@ -136,7 +136,7 @@ class Optioning
136
136
  end
137
137
 
138
138
  def options
139
- @options ||= []
139
+ @options ||= {}
140
140
  end
141
141
 
142
142
  # Cleanup the options trashing up the deprecated options in favor the
@@ -145,7 +145,8 @@ class Optioning
145
145
  # @return [Hash] @options already filtered
146
146
  def replace_deprecations
147
147
  deprecations.each do |deprecation|
148
- options[deprecation.replacement] = options.delete deprecation.option
148
+ deprecated_value = options.delete deprecation.option
149
+ options[deprecation.replacement] ||= deprecated_value
149
150
  end
150
151
  options
151
152
  end
data/script/console ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ exec "pry -r optioning -I lib"
@@ -29,6 +29,21 @@ describe Optioning do
29
29
  optioning.process.must_be_same_as optioning
30
30
  end
31
31
 
32
+ it "doesn't mutate the original Array" do
33
+ original = [:path, option: "value"]
34
+ passed_options = original.dup
35
+ optioning = Optioning.new passed_options
36
+ optioning.deprecate :old_option, :option
37
+ optioning.process
38
+ passed_options.must_be :==, original
39
+ end
40
+
41
+ it "doesn't nillify option when deprecation exists but current is used" do
42
+ optioning.deprecate :lol, :omg
43
+ optioning.process
44
+ optioning.on(:omg).must_be :==, "O YEAH!"
45
+ end
46
+
32
47
  it "shows deprecations and unrecognized warnings" do
33
48
  optioning.process
34
49
  $stderr.string.must_be :==,[
@@ -74,5 +89,12 @@ describe Optioning do
74
89
  # impossible to use lambda.must_be_same_as, maybe a bug?
75
90
  optioning.on(:to_hash).object_id.must_be :==, to_hash_lambda.object_id
76
91
  end
92
+
93
+ describe "when there is no options" do
94
+ let(:optioning) { Optioning.new [:path, :commit] }
95
+ it "not breaks when tries to recover the option" do
96
+ optioning.on :x
97
+ end
98
+ end
77
99
  end
78
100
  end
@@ -56,5 +56,12 @@ describe Optioning do
56
56
  $stderr.string.must_be :==, "NOTE: unrecognized option `:no_one_knows` used."+
57
57
  "\nYou should use only the following: `:lol`, `:from`, `:to`"
58
58
  end
59
+
60
+ it "just send the 'You should use only...' message when there are unrecognized options" do
61
+ optioning = Optioning.new [omg_lol_bbq: "recognized!"]
62
+ optioning.recognize :omg_lol_bbq
63
+ optioning.unrecognized_warn
64
+ $stderr.string.must_be :==, ""
65
+ end
59
66
  end
60
67
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Valeriano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
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
26
  version: '1.5'
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
33
  version: '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
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest-reporters
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.0'
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
54
  version: '1.0'
55
55
  description: An easy way to retrieve, store, filter and deprecate `options` passed
@@ -61,8 +61,9 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
65
- - .travis.yml
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - CHANGELOG.md
66
67
  - Gemfile
67
68
  - LICENSE.txt
68
69
  - README.md
@@ -73,6 +74,7 @@ files:
73
74
  - lib/optioning.rb
74
75
  - lib/optioning/version.rb
75
76
  - optioning.gemspec
77
+ - script/console
76
78
  - tasks/lines.rake
77
79
  - tasks/test.rake
78
80
  - test/deprecation_test.rb
@@ -89,17 +91,17 @@ require_paths:
89
91
  - lib
90
92
  required_ruby_version: !ruby/object:Gem::Requirement
91
93
  requirements:
92
- - - '>='
94
+ - - ">="
93
95
  - !ruby/object:Gem::Version
94
96
  version: '0'
95
97
  required_rubygems_version: !ruby/object:Gem::Requirement
96
98
  requirements:
97
- - - '>='
99
+ - - ">="
98
100
  - !ruby/object:Gem::Version
99
101
  version: '0'
100
102
  requirements: []
101
103
  rubyforge_project:
102
- rubygems_version: 2.1.11
104
+ rubygems_version: 2.2.2
103
105
  signing_key:
104
106
  specification_version: 4
105
107
  summary: 'An object oriented way to treat our beloved last parameter: Hash.'
@@ -108,3 +110,4 @@ test_files:
108
110
  - test/optioning_test.rb
109
111
  - test/test_helper.rb
110
112
  - test/unrecognized_option_test.rb
113
+ has_rdoc: