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.



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/work/dotfile.rb', line 4

def path
  @path
end

Class Method Details

.locateObject



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

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

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  File.exists? @path
end

#readObject



18
19
20
# File 'lib/work/dotfile.rb', line 18

def read
  File.readlines(path).collect { |d| d.strip }.sort rescue []
end

#write(data) ⇒ Object



22
23
24
25
26
# File 'lib/work/dotfile.rb', line 22

def write(data)
  File.open(path, 'w+') do |f|
    f.write(data.is_a?(Array) ? data.join("\n") : data)
  end
end