Skip to content

Commit

Permalink
Merge pull request #1247 from gpakosz/pattern-from-symbol
Browse files Browse the repository at this point in the history
Allow creation of Pattern from Symbol
  • Loading branch information
denisdefreyne committed Nov 16, 2017
2 parents dc8cd72 + ec8ec14 commit 37da46f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/nanoc/base/entities/pattern.rb
Expand Up @@ -14,6 +14,8 @@ def self.from(obj)
Nanoc::Int::StringPattern.new(obj)
when Regexp
Nanoc::Int::RegexpPattern.new(obj)
when Symbol
Nanoc::Int::StringPattern.new(obj.to_s)
else
raise ArgumentError, "Do not know how to convert `#{obj.inspect}` into a Nanoc::Pattern"
end
Expand Down
6 changes: 6 additions & 0 deletions spec/nanoc/base/entities/pattern_spec.rb
Expand Up @@ -21,6 +21,12 @@
expect(pattern.match?('/foo/xyz/bar.html')).to eql(false)
end

it 'converts from symbol' do
pattern = described_class.from(:'/foo/x[ab]z/bar.*')
expect(pattern.match?('/foo/xaz/bar.html')).to eql(true)
expect(pattern.match?('/foo/xyz/bar.html')).to eql(false)
end

it 'errors on other inputs' do
expect { described_class.from(123) }.to raise_error(ArgumentError)
end
Expand Down

0 comments on commit 37da46f

Please sign in to comment.