Class: Rigor::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/configuration.rb,
lib/rigor/configuration/severity_profile.rb

Overview

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Modules: SeverityProfile

Constant Summary collapse

DEFAULT_PATH =
".rigor.yml"
DEFAULTS =
{
  "target_ruby" => "4.0",
  "paths" => ["lib"],
  "plugins" => [],
  "disable" => [],
  "libraries" => [],
  "signature_paths" => nil,
  "fold_platform_specific_paths" => false,
  "cache" => {
    "path" => ".rigor/cache"
  },
  "plugins_io" => {
    "network" => "disabled",
    "allowed_paths" => []
  },
  "severity_profile" => "balanced",
  "severity_overrides" => {}
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = DEFAULTS) ⇒ Configuration

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rigor/configuration.rb', line 44

def initialize(data = DEFAULTS) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
  cache = DEFAULTS.fetch("cache").merge(data.fetch("cache", {}))
  plugins_io = DEFAULTS.fetch("plugins_io").merge(data.fetch("plugins_io", {}))

  @target_ruby = data.fetch("target_ruby", DEFAULTS.fetch("target_ruby")).to_s
  @paths = Array(data.fetch("paths", DEFAULTS.fetch("paths"))).map(&:to_s)
  @plugins = Array(data.fetch("plugins", DEFAULTS.fetch("plugins"))).map do |entry|
    coerce_plugin_entry(entry)
  end.freeze
  @disabled_rules = Array(data.fetch("disable", DEFAULTS.fetch("disable"))).map(&:to_s).freeze
  @libraries = Array(data.fetch("libraries", DEFAULTS.fetch("libraries"))).map(&:to_s).freeze
  sig_paths = data.fetch("signature_paths", DEFAULTS.fetch("signature_paths"))
  @signature_paths = sig_paths.nil? ? nil : Array(sig_paths).map(&:to_s).freeze
  @fold_platform_specific_paths = data.fetch(
    "fold_platform_specific_paths", DEFAULTS.fetch("fold_platform_specific_paths")
  ) == true
  @cache_path = cache.fetch("path").to_s
  @plugins_io_network = coerce_network_policy(plugins_io.fetch("network"))
  @plugins_io_allowed_paths = Array(plugins_io.fetch("allowed_paths")).map(&:to_s).freeze
  @severity_profile = coerce_severity_profile(
    data.fetch("severity_profile", DEFAULTS.fetch("severity_profile"))
  )
  @severity_overrides = coerce_severity_overrides(
    data.fetch("severity_overrides", DEFAULTS.fetch("severity_overrides"))
  )
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def cache_path
  @cache_path
end

#disabled_rulesObject (readonly)

Returns the value of attribute disabled_rules.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def disabled_rules
  @disabled_rules
end

#fold_platform_specific_pathsObject (readonly)

Returns the value of attribute fold_platform_specific_paths.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def fold_platform_specific_paths
  @fold_platform_specific_paths
end

#librariesObject (readonly)

Returns the value of attribute libraries.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def libraries
  @libraries
end

#pathsObject (readonly)

Returns the value of attribute paths.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def paths
  @paths
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def plugins
  @plugins
end

#plugins_io_allowed_pathsObject (readonly)

Returns the value of attribute plugins_io_allowed_paths.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def plugins_io_allowed_paths
  @plugins_io_allowed_paths
end

#plugins_io_networkObject (readonly)

Returns the value of attribute plugins_io_network.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def plugins_io_network
  @plugins_io_network
end

#severity_overridesObject (readonly)

Returns the value of attribute severity_overrides.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def severity_overrides
  @severity_overrides
end

#severity_profileObject (readonly)

Returns the value of attribute severity_profile.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def severity_profile
  @severity_profile
end

#signature_pathsObject (readonly)

Returns the value of attribute signature_paths.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def signature_paths
  @signature_paths
end

#target_rubyObject (readonly)

Returns the value of attribute target_ruby.



29
30
31
# File 'lib/rigor/configuration.rb', line 29

def target_ruby
  @target_ruby
end

Class Method Details

.load(path = DEFAULT_PATH) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rigor/configuration.rb', line 34

def self.load(path = DEFAULT_PATH)
  data = if File.exist?(path)
           YAML.safe_load_file(path, aliases: false) || {}
         else
           {}
         end

  new(DEFAULTS.merge(data))
end

Instance Method Details

#to_hObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rigor/configuration.rb', line 71

def to_h
  {
    "target_ruby" => target_ruby,
    "paths" => paths,
    "plugins" => plugins,
    "disable" => disabled_rules,
    "libraries" => libraries,
    "signature_paths" => signature_paths,
    "fold_platform_specific_paths" => fold_platform_specific_paths,
    "cache" => {
      "path" => cache_path
    },
    "plugins_io" => {
      "network" => plugins_io_network.to_s,
      "allowed_paths" => plugins_io_allowed_paths
    },
    "severity_profile" => severity_profile.to_s,
    "severity_overrides" => severity_overrides.to_h { |k, v| [k, v.to_s] }
  }
end