Class: Work::DotFile
- Inherits:
-
Object
- Object
- Work::DotFile
- Defined in:
- lib/work/dotfile.rb
Instance Attribute Summary collapse
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#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! ⇒ Object
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
#domains ⇒ Object
Returns the value of attribute domains.
6 7 8 |
# File 'lib/work/dotfile.rb', line 6 def domains @domains end |
#ip ⇒ Object
Returns the value of attribute ip.
6 7 8 |
# File 'lib/work/dotfile.rb', line 6 def ip @ip end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/work/dotfile.rb', line 6 def path @path end |
Class Method Details
.locate ⇒ Object
9 10 11 |
# File 'lib/work/dotfile.rb', line 9 def self.locate @dotfile ||= self.new File.(File.join('~', '.work')) end |
Instance Method Details
#exists? ⇒ 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 |