Class: Rigor::Configuration

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

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"
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = DEFAULTS) ⇒ Configuration

rubocop:disable Metrics/AbcSize



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rigor/configuration.rb', line 34

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

  @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(&:to_s)
  @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
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def cache_path
  @cache_path
end

#disabled_rulesObject (readonly)

Returns the value of attribute disabled_rules.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def disabled_rules
  @disabled_rules
end

#fold_platform_specific_pathsObject (readonly)

Returns the value of attribute fold_platform_specific_paths.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def fold_platform_specific_paths
  @fold_platform_specific_paths
end

#librariesObject (readonly)

Returns the value of attribute libraries.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def libraries
  @libraries
end

#pathsObject (readonly)

Returns the value of attribute paths.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def paths
  @paths
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def plugins
  @plugins
end

#signature_pathsObject (readonly)

Returns the value of attribute signature_paths.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def signature_paths
  @signature_paths
end

#target_rubyObject (readonly)

Returns the value of attribute target_ruby.



21
22
23
# File 'lib/rigor/configuration.rb', line 21

def target_ruby
  @target_ruby
end

Class Method Details

.load(path = DEFAULT_PATH) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rigor/configuration.rb', line 24

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rigor/configuration.rb', line 50

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
    }
  }
end