Class: Obst::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/obst/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
# File 'lib/obst/config.rb', line 5

def initialize(dir)
  @cfg = nil
  location = File.join(dir, '.obst.json')
  return @cfg = {} unless File.exist?(location)

  File.open(location) do |f|
    @cfg = JSON.parse(f.read)
  end
end

Instance Method Details

#dig(*path) ⇒ Object



15
16
17
# File 'lib/obst/config.rb', line 15

def dig(*path)
  @cfg.dig(*path)
end

#dig_any(*paths) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/obst/config.rb', line 19

def dig_any(*paths)
  paths.each do |path|
    v = dig(*path)
    return v if v
  end
  nil
end