Class: GetToWork::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/get_to_work/config_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigFile

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

#dataObject (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/get_to_work/config_file.rb', line 37

def self.exist?
  File.exist? path
end

.filenameObject



45
46
47
# File 'lib/get_to_work/config_file.rb', line 45

def self.filename
  ".get-to-work"
end

.pathObject



41
42
43
# File 'lib/get_to_work/config_file.rb', line 41

def self.path
  File.join(Dir.pwd, filename)
end

.saveObject



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

#saveObject



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