Skip to content

Commit

Permalink
Added support for Regexp
Browse files Browse the repository at this point in the history
Used to work on 3.6
See e2775e2
  • Loading branch information
spk committed May 17, 2015
1 parent 4078a1b commit e7521a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/slop/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def limit
end
end

# Cast the option argument to a Regexp.
class RegexpOption < Option
def call(value)
Regexp.new(value)
end
end

# An option that discards the return value, inherits from Bool
# since it does not expect an argument.
class NullOption < BoolOption
Expand Down
13 changes: 13 additions & 0 deletions test/types_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,16 @@
assert_equal({}, @result.to_hash)
end
end

describe Slop::RegexpOption do
before do
@options = Slop::Options.new
@exclude = @options.regexp "--exclude"
@exclude_value = "redirect|news"
@result = @options.parse %W(--exclude #{@exclude_value})
end

it "returns the value as a Regexp" do
assert_equal Regexp.new(@exclude_value), @result[:exclude]
end
end

0 comments on commit e7521a6

Please sign in to comment.