Class: Swagcov::Dotfile

Inherits:
Object
  • Object
show all
Defined in:
lib/swagcov/dotfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(basename: ::Swagcov::DOTFILE, todo_basename: ::Swagcov::TODOFILE, skip_todo: false) ⇒ Dotfile

Returns a new instance of Dotfile.



5
6
7
8
9
10
11
12
13
# File 'lib/swagcov/dotfile.rb', line 5

def initialize basename: ::Swagcov::DOTFILE, todo_basename: ::Swagcov::TODOFILE, skip_todo: false
  @dotfile = load_yaml(basename, required: true)

  raise ::Swagcov::Errors::BadConfiguration, "Invalid config file (#{::Swagcov::DOTFILE})" unless valid?

  @todo_file = load_yaml(todo_basename) unless skip_todo
  @ignored_regex = path_config_regex(ignored_config)
  @only_regex = path_config_regex(only_config)
end

Instance Method Details

#docs_configObject



32
33
34
# File 'lib/swagcov/dotfile.rb', line 32

def docs_config
  @docs_config ||= dotfile.dig("docs", "paths")
end

#ignore_path?(path, verb:) ⇒ Boolean

Returns:

  • (Boolean)


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

def ignore_path? path, verb:
  return false unless @ignored_config

  ignore_all_path_actions = @ignored_regex.match?(path)

  ignored_verbs =
    @ignored_config.select { |config| config[path]&.is_a?(::Array) }.map(&:values).flatten.map(&:downcase)

  return ignore_all_path_actions if ignored_verbs.empty?

  ignored_verbs.any?(verb.downcase)
end

#ignored_configObject



36
37
38
39
40
41
42
# File 'lib/swagcov/dotfile.rb', line 36

def ignored_config
  dotfile_routes = dotfile.dig("routes", "paths", "ignore").to_a
  todo_routes = todo_file ? todo_file.dig("routes", "paths", "ignore").to_a : []
  routes = dotfile_routes + todo_routes

  @ignored_config ||= routes.empty? ? nil : routes
end

#only_configObject



44
45
46
# File 'lib/swagcov/dotfile.rb', line 44

def only_config
  @only_config ||= dotfile.dig("routes", "paths", "only")
end

#only_path_mismatch?(path) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/swagcov/dotfile.rb', line 28

def only_path_mismatch? path
  @only_config && !@only_regex.match?(path)
end