Class: OsCtld::RunState::StartConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/run_state/start_config.rb

Overview

One-time config for osctld

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ StartConfig

Returns a new instance of StartConfig.

Parameters:

  • path (String)


10
11
12
13
# File 'lib/osctld/run_state/start_config.rb', line 10

def initialize(path)
  @path = path
  open_config
end

Instance Attribute Details

#cfgObject (readonly, protected)

Returns the value of attribute cfg.



27
28
29
# File 'lib/osctld/run_state/start_config.rb', line 27

def cfg
  @cfg
end

#pathString (readonly)

Returns:

  • (String)


7
8
9
# File 'lib/osctld/run_state/start_config.rb', line 7

def path
  @path
end

Instance Method Details

#closeObject



19
20
21
22
23
# File 'lib/osctld/run_state/start_config.rb', line 19

def close
  File.unlink(path) if exist?
rescue Errno::ENOENT
  # ignore
end

#exist?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/osctld/run_state/start_config.rb', line 15

def exist?
  @exist
end

#open_configObject (protected)



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctld/run_state/start_config.rb', line 29

def open_config
  @cfg = {}

  begin
    data = File.read(path)
  rescue Errno::ENOENT
    @exist = false
    return
  end

  @exist = true
  @cfg = JSON.parse(data)
end