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" => [],
  "cache" => {
    "path" => ".rigor/cache"
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = DEFAULTS) ⇒ Configuration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
36
# File 'lib/rigor/configuration.rb', line 29

def initialize(data = DEFAULTS)
  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)
  @cache_path = cache.fetch("path").to_s
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



17
18
19
# File 'lib/rigor/configuration.rb', line 17

def cache_path
  @cache_path
end

#pathsObject (readonly)

Returns the value of attribute paths.



17
18
19
# File 'lib/rigor/configuration.rb', line 17

def paths
  @paths
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



17
18
19
# File 'lib/rigor/configuration.rb', line 17

def plugins
  @plugins
end

#target_rubyObject (readonly)

Returns the value of attribute target_ruby.



17
18
19
# File 'lib/rigor/configuration.rb', line 17

def target_ruby
  @target_ruby
end

Class Method Details

.load(path = DEFAULT_PATH) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/rigor/configuration.rb', line 19

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



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

def to_h
  {
    "target_ruby" => target_ruby,
    "paths" => paths,
    "plugins" => plugins,
    "cache" => {
      "path" => cache_path
    }
  }
end