Skip to content

Commit

Permalink
plumb Silencer#initialize(options) to configure(options) and update d…
Browse files Browse the repository at this point in the history
…eprecation comments
  • Loading branch information
ColinDKelley committed Aug 15, 2021
1 parent 8b17254 commit 755309a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/listen/silencer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,21 @@ class Silencer
| ~
)$}x.freeze

# TODO: deprecate these mutators; use attr_reader instead
attr_accessor :only_patterns, :ignore_patterns

def initialize
configure({})
def initialize(options = {})
configure(options)
end

# TODO: deprecate this mutator
def configure(options)
@only_patterns = options[:only] ? Array(options[:only]) : nil
@ignore_patterns = _init_ignores(options[:ignore], options[:ignore!])
end

# Note: relative_path is temporarily expected to be a relative Pathname to
# make refactoring easier (ideally, it would take a string)

# TODO: switch type and path places - and verify
def silenced?(relative_path, type)
path = relative_path.to_s
path = relative_path.to_s # in case it is a Pathname

_ignore?(path) || (only_patterns && type == :file && !_only?(path))
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/listen/silencer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

RSpec.describe Listen::Silencer do
let(:options) { {} }
before { subject.configure(options) }
subject { described_class.new(options) }

describe '#silenced?' do
it { should accept(:file, Pathname('some_dir').join("some_file.rb")) }
Expand Down

0 comments on commit 755309a

Please sign in to comment.