Class: Work::DotFile

Inherits:
Object
  • Object
show all
Defined in:
lib/work/dotfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DotFile

Returns a new instance of DotFile.



13
14
15
16
# File 'lib/work/dotfile.rb', line 13

def initialize(path)
  @path = path
  read!
end

Instance Attribute Details

#domainsObject

Returns the value of attribute domains.



6
7
8
# File 'lib/work/dotfile.rb', line 6

def domains
  @domains
end

#ipObject

Returns the value of attribute ip.



6
7
8
# File 'lib/work/dotfile.rb', line 6

def ip
  @ip
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/work/dotfile.rb', line 6

def path
  @path
end

Class Method Details

.locateObject



9
10
11
# File 'lib/work/dotfile.rb', line 9

def self.locate
  @dotfile ||= self.new File.expand_path(File.join('~', '.work'))
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/work/dotfile.rb', line 26

def exists?
  File.exists? @path
end

#read!Object



30
31
32
33
34
35
36
# File 'lib/work/dotfile.rb', line 30

def read!
  if exists?
    data = YAML.load_file(path)
    self.ip = data["ip"] if data.has_key?("ip")
    self.domains = data["domains"].sort if data.has_key?("domains")
  end
end

#write!Object



38
39
40
41
42
# File 'lib/work/dotfile.rb', line 38

def write!
  File.open(path, 'w+') do |f|
    f.write YAML::dump({ "ip" => ip, "domains" => domains })
  end
end