Class: Rigor::Configuration
- Inherits:
-
Object
- Object
- Rigor::Configuration
- 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, "cache" => { "path" => ".rigor/cache" } }.freeze
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
-
#disabled_rules ⇒ Object
readonly
Returns the value of attribute disabled_rules.
-
#libraries ⇒ Object
readonly
Returns the value of attribute libraries.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#signature_paths ⇒ Object
readonly
Returns the value of attribute signature_paths.
-
#target_ruby ⇒ Object
readonly
Returns the value of attribute target_ruby.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data = DEFAULTS) ⇒ Configuration
constructor
rubocop:disable Metrics/AbcSize.
- #to_h ⇒ Object
Constructor Details
#initialize(data = DEFAULTS) ⇒ Configuration
rubocop:disable Metrics/AbcSize
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rigor/configuration.rb', line 33 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 @cache_path = cache.fetch("path").to_s end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def cache_path @cache_path end |
#disabled_rules ⇒ Object (readonly)
Returns the value of attribute disabled_rules.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def disabled_rules @disabled_rules end |
#libraries ⇒ Object (readonly)
Returns the value of attribute libraries.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def libraries @libraries end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def paths @paths end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def plugins @plugins end |
#signature_paths ⇒ Object (readonly)
Returns the value of attribute signature_paths.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def signature_paths @signature_paths end |
#target_ruby ⇒ Object (readonly)
Returns the value of attribute target_ruby.
20 21 22 |
# File 'lib/rigor/configuration.rb', line 20 def target_ruby @target_ruby end |
Class Method Details
.load(path = DEFAULT_PATH) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rigor/configuration.rb', line 23 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_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rigor/configuration.rb', line 46 def to_h { "target_ruby" => target_ruby, "paths" => paths, "plugins" => plugins, "disable" => disabled_rules, "libraries" => libraries, "signature_paths" => signature_paths, "cache" => { "path" => cache_path } } end |