class Leftovers::Config

Attributes

name[R]

:nocov:

Public Class Methods

new(name, path: nil, content: nil) click to toggle source
# File lib/leftovers/config.rb, line 13
def initialize(name, path: nil, content: nil)
  @name = name.to_sym
  @path = path
  @content = content
end

Public Instance Methods

dynamic() click to toggle source
# File lib/leftovers/config.rb, line 35
def dynamic
  @dynamic ||= ::Leftovers::ProcessorBuilders::Dynamic.build(yaml[:dynamic])
end
exclude_paths() click to toggle source
# File lib/leftovers/config.rb, line 23
def exclude_paths
  @exclude_paths ||= Array(yaml[:exclude_paths])
end
gems() click to toggle source
# File lib/leftovers/config.rb, line 19
def gems
  @gems ||= Array(yaml[:gems]).map(&:to_sym)
end
include_paths() click to toggle source
# File lib/leftovers/config.rb, line 27
def include_paths
  @include_paths ||= Array(yaml[:include_paths])
end
keep() click to toggle source
# File lib/leftovers/config.rb, line 39
def keep
  @keep ||= ::Leftovers::MatcherBuilders::Node.build(yaml[:keep])
end
requires() click to toggle source
# File lib/leftovers/config.rb, line 47
def requires
  @requires ||= Array(yaml[:requires])
end
test_only() click to toggle source
# File lib/leftovers/config.rb, line 43
def test_only
  @test_only ||= ::Leftovers::MatcherBuilders::Node.build(yaml[:test_only])
end
test_paths() click to toggle source
# File lib/leftovers/config.rb, line 31
def test_paths
  @test_paths ||= Array(yaml[:test_paths])
end

Private Instance Methods

content() click to toggle source
# File lib/leftovers/config.rb, line 53
def content
  @content ||= ::File.exist?(path) ? ::File.read(path) : ''
end
parse_yaml() click to toggle source
# File lib/leftovers/config.rb, line 65
def parse_yaml
  # :nocov:
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
    Psych.safe_load(content, filename: path) || {}
  else
    Psych.safe_load(content, [], [], false, path) || {}
  end
  # :nocov:
rescue ::Psych::SyntaxError => e
  warn "\e[31mConfig SyntaxError: #{e.message}\e[0m"
  Leftovers.exit 1
end
path() click to toggle source
# File lib/leftovers/config.rb, line 57
def path
  @path ||= ::File.expand_path("../config/#{name}.yml", __dir__)
end
yaml() click to toggle source
# File lib/leftovers/config.rb, line 61
def yaml
  @yaml ||= ::Leftovers::ConfigValidator.validate_and_process!(parse_yaml, path)
end