Module: Silencer

Defined in:
lib/silencer.rb,
lib/silencer/version.rb,
sig/silencer.rbs

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =

Returns:

  • (String)
'0.5.0'

Class Method Summary collapse

Class Method Details

.config_file_path(file) ⇒ String

See the writing guide of rbs: https://github.com/ruby/rbs#guides

Returns:

  • (String)


4
5
6
7
8
9
10
# File 'sig/silencer.rbs', line 4

def self.config_file_path(file)
  if defined? ::Bundler
    ::Bundler.root.join(file).to_s
  else
    file
  end
end

.ignore_warnings(file = '.silencer.yml') ⇒ Object

Returns:

  • (Object)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/silencer.rb', line 14

def self.ignore_warnings(file = '.silencer.yml')
  YAML.load_file(config_file_path(file)).each do |name, attrs|
    version = attrs['version']
    spec = Gem::Specification.find_by_name(name)
    raise Error.new(name, version, spec.version.to_s) unless version == spec.version.to_s
    Array(attrs['patterns']).each do |pattern|
      args = [Regexp.new(pattern)]
      args << spec.gem_dir unless attrs.fetch('exclude_path_prefix', false)
      Warning.ignore(*args)
    end
  rescue Gem::LoadError
    # ignore
  end
end