Class: ArisControl::Persistence

Inherits:
Object
  • Object
show all
Defined in:
lib/aris-control/persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = default_config) ⇒ Persistence

Returns a new instance of Persistence.



8
9
10
11
12
# File 'lib/aris-control/persistence.rb', line 8

def initialize(config = default_config)
  @config = config
  @config_file_path = Pathname.new config[:config_file_path]
  @users_file_path  = Pathname.new config[:users_file_path]
end

Instance Attribute Details

#config_file_pathObject (readonly)

Returns the value of attribute config_file_path.



6
7
8
# File 'lib/aris-control/persistence.rb', line 6

def config_file_path
  @config_file_path
end

#users_file_pathObject (readonly)

Returns the value of attribute users_file_path.



6
7
8
# File 'lib/aris-control/persistence.rb', line 6

def users_file_path
  @users_file_path
end

Instance Method Details

#default_configObject



25
26
27
28
29
30
# File 'lib/aris-control/persistence.rb', line 25

def default_config
  {
    config_file_path: '/opt/aris/config/aris.cfg',
    users_file_path:  '/opt/aris/config/users.yml',
  }
end

#load_usersObject



20
21
22
23
# File 'lib/aris-control/persistence.rb', line 20

def load_users
  store_users({}) unless users_file_path.exist?
  YAML.load(IO.binread(users_file_path)) || {}
end

#store_users(users) ⇒ Object



14
15
16
17
18
# File 'lib/aris-control/persistence.rb', line 14

def store_users(users)
  users ||= {}
  IO.binwrite(users_file_path, YAML.dump(users))
  users
end