Class: GetToWork::ConfigFile
- Inherits:
-
Object
- Object
- GetToWork::ConfigFile
- Includes:
- Singleton
- Defined in:
- lib/get_to_work/config_file.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #save ⇒ Object
- #setup_data(path) ⇒ Object
Constructor Details
#initialize ⇒ ConfigFile
Returns a new instance of ConfigFile.
9 10 11 |
# File 'lib/get_to_work/config_file.rb', line 9 def initialize setup_data(self.class.path) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/get_to_work/config_file.rb', line 6 def data @data end |
Class Method Details
.exist? ⇒ Boolean
37 38 39 |
# File 'lib/get_to_work/config_file.rb', line 37 def self.exist? File.exist? path end |
.filename ⇒ Object
45 46 47 |
# File 'lib/get_to_work/config_file.rb', line 45 def self.filename ".get-to-work" end |
.path ⇒ Object
41 42 43 |
# File 'lib/get_to_work/config_file.rb', line 41 def self.path File.join(Dir.pwd, filename) end |
.save ⇒ Object
29 30 31 |
# File 'lib/get_to_work/config_file.rb', line 29 def self.save instance.save end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/get_to_work/config_file.rb', line 21 def [](key) @data[key] end |
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/get_to_work/config_file.rb', line 25 def []=(key, value) @data[key] = value end |
#save ⇒ Object
33 34 35 |
# File 'lib/get_to_work/config_file.rb', line 33 def save File.open(self.class.path, "w") { |f| f.write YAML.dump(@data) } end |
#setup_data(path) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/get_to_work/config_file.rb', line 13 def setup_data(path) @data = begin YAML.load_file(path) rescue Errno::ENOENT {} end end |