Class: Pwnix::Api::Client::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pwnix-api-client/config/config_file.rb

Direct Known Subclasses

Config

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ ConfigFile

Returns a new instance of ConfigFile.



6
7
8
9
# File 'lib/pwnix-api-client/config/config_file.rb', line 6

def initialize(config_file)
  @config_file=config_file
  @config_hash = JSON.parse(File.read(@config_file))
end

Instance Method Details

#[](key, value = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/pwnix-api-client/config/config_file.rb', line 11

def [](key, value=nil)
  if value
    @config_hash[key] = value
  else
    @config_hash[key]
  end
end

#readObject



19
20
21
# File 'lib/pwnix-api-client/config/config_file.rb', line 19

def read
  @config_hash = JSON.parse(File.read(@config_file))
end

#writeObject



23
24
25
# File 'lib/pwnix-api-client/config/config_file.rb', line 23

def write
  File.open(@config_file,'w'){ |f| JSON.dump(@config_hash, f) }
end