slop 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,8 @@
1
+ 2.4.1 (2011-12-08)
2
+ ------------------
3
+
4
+ * Ensure optional arguments are returned correctly
5
+
1
6
  2.4.0 (2011-11-26)
2
7
  ------------------
3
8
 
data/Rakefile CHANGED
@@ -1,3 +1,9 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ rescue LoadError
4
+ end
5
+
6
+ desc 'Run the test suite'
1
7
  task :test do
2
8
  $:.unshift './test'
3
9
  Dir.glob("test/*_test.rb").each { |test| require "./#{test}" }
data/lib/slop.rb CHANGED
@@ -2,7 +2,7 @@ class Slop
2
2
  include Enumerable
3
3
 
4
4
  # @return [String] The current version string
5
- VERSION = '2.4.0'
5
+ VERSION = '2.4.1'
6
6
 
7
7
  # Slops standard Error class. All exception classes should
8
8
  # inherit from this class
@@ -151,12 +151,18 @@ class Slop
151
151
  return if value.nil?
152
152
 
153
153
  case @argument_type
154
- when 'array'; @argument_value unless !expects_argument?
155
- when 'range'; value_to_range value unless !expects_argument?
156
- when 'float'; value.to_s.to_f unless !expects_argument?
157
- when 'string', 'str'; value.to_s unless !expects_argument?
158
- when 'symbol', 'sym'; value.to_s.to_sym unless !expects_argument?
159
- when 'integer', 'int'; value.to_s.to_i unless !expects_argument?
154
+ when 'array'
155
+ arg_value(@argument_value)
156
+ when 'range'
157
+ arg_value(value_to_range(value))
158
+ when 'float'
159
+ arg_value(value.to_s.to_f)
160
+ when 'string', 'str'
161
+ arg_value(value.to_s)
162
+ when 'symbol', 'sym'
163
+ arg_value(value.to_s.to_sym)
164
+ when 'integer', 'int'
165
+ arg_value(value.to_s.to_i)
160
166
  else
161
167
  value
162
168
  end
@@ -222,6 +228,12 @@ class Slop
222
228
 
223
229
  private
224
230
 
231
+ def arg_value(value)
232
+ if accepts_optional_argument? || expects_argument?
233
+ value
234
+ end
235
+ end
236
+
225
237
  def value_to_range(value)
226
238
  case value.to_s
227
239
  when /\A(-?\d+?)(\.\.\.?|-|,)(-?\d+)\z/
data/slop.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'slop'
3
- s.version = '2.4.0'
3
+ s.version = '2.4.1'
4
4
  s.summary = 'Option gathering made easy'
5
5
  s.description = 'A simple DSL for gathering options and parsing the command line'
6
6
  s.author = 'Lee Jarvis'
data/test/option_test.rb CHANGED
@@ -94,6 +94,9 @@ class OptionTest < TestCase
94
94
  assert_equal nil, option_value(%w/-i/, :i, :as => :float)
95
95
  assert_equal nil, option_value(%w/-i/, :i, :as => :array)
96
96
  assert_equal nil, option_value(%w/-i/, :i, :as => :range)
97
+
98
+ assert_equal 1, option_value(%w/-i 1/, :i, :optional => true, :as => :range)
99
+ assert_equal nil, option_value(%w/-i/, :i, :optional => true, :as => :range)
97
100
  end
98
101
 
99
102
  test 'ranges' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.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: 2011-11-26 00:00:00.000000000Z
12
+ date: 2011-12-08 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A simple DSL for gathering options and parsing the command line
15
15
  email: lee@jarvis.co
@@ -17,9 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gemtest
21
20
  - .gitignore
22
- - .yardopts
23
21
  - CHANGES.md
24
22
  - LICENSE
25
23
  - README.md
@@ -50,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
48
  version: '0'
51
49
  requirements: []
52
50
  rubyforge_project:
53
- rubygems_version: 1.8.11
51
+ rubygems_version: 1.8.10
54
52
  signing_key:
55
53
  specification_version: 3
56
54
  summary: Option gathering made easy
data/.gemtest DELETED
File without changes
data/.yardopts DELETED
@@ -1,6 +0,0 @@
1
- --hide-void-return
2
- -m markdown
3
- --title "Slop - Option gathering made easy"
4
- lib/**/*.rb
5
- --no-private
6
- --readme README.md