Class: Pwnix::Api::Client::ConfigFile
- Inherits:
-
Object
- Object
- Pwnix::Api::Client::ConfigFile
- Defined in:
- lib/pwnix-api-client/config/config_file.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](key, value = nil) ⇒ Object
-
#initialize(config_file) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #read ⇒ Object
- #write ⇒ Object
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 |
#read ⇒ Object
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 |
#write ⇒ Object
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 |