Class: Work::DotFile
- Inherits:
-
Object
- Object
- Work::DotFile
- Defined in:
- lib/work/dotfile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(path) ⇒ DotFile
constructor
A new instance of DotFile.
- #read ⇒ Object
- #write(data) ⇒ Object
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
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/work/dotfile.rb', line 4 def path @path end |
Class Method Details
.locate ⇒ Object
6 7 8 |
# File 'lib/work/dotfile.rb', line 6 def self.locate @dotfile ||= self.new File.(File.join('~', '.work')) end |
Instance Method Details
#exists? ⇒ Boolean
14 15 16 |
# File 'lib/work/dotfile.rb', line 14 def exists? File.exists? @path end |
#read ⇒ Object
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 |