Class: Norn::LocalConfigReader

Inherits:
Object
  • Object
show all
Defined in:
lib/norn/local_config_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path = nil) ⇒ LocalConfigReader

Returns a new instance of LocalConfigReader.



8
9
10
# File 'lib/norn/local_config_reader.rb', line 8

def initialize(root_path = nil)
  @root_path = root_path || Dir.pwd
end

Instance Attribute Details

#root_pathObject (readonly)

Returns the value of attribute root_path.



6
7
8
# File 'lib/norn/local_config_reader.rb', line 6

def root_path
  @root_path
end

Instance Method Details

#local_config_pathsObject



12
13
14
15
16
17
18
# File 'lib/norn/local_config_reader.rb', line 12

def local_config_paths
  [
    File.join(@root_path, ".norn.yml"),
    File.join(@root_path, ".norn.yaml"),
    File.join(@root_path, ".norn.json")
  ]
end

#readObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/norn/local_config_reader.rb', line 20

def read
  local_config_paths.each do |path|
    next unless File.exist?(path)

    begin
      if path.end_with?(".json")
        return parse_json(path)
      else
        return parse_yaml(path)
      end
    rescue => e
      warn "Norn Config Error: Failed to parse #{path} - #{e.message}"
    end
  end
  {}
end