Class: RPW::ClientData
- Inherits:
-
Object
- Object
- RPW::ClientData
- Defined in:
- lib/rpw/client_data.rb
Constant Summary collapse
- DOTFILE_NAME =
".rpw_info"
Class Method Summary collapse
- .create_in_home! ⇒ Object
- .create_in_pwd! ⇒ Object
- .delete_filestore ⇒ Object
- .exists? ⇒ Boolean
- .filestore_location ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ ClientData
constructor
A new instance of ClientData.
Constructor Details
#initialize ⇒ ClientData
Returns a new instance of ClientData.
8 9 10 |
# File 'lib/rpw/client_data.rb', line 8 def initialize data # access file to load end |
Class Method Details
.create_in_home! ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rpw/client_data.rb', line 32 def self.create_in_home! unless File.directory?(File.("~/.rpw/")) FileUtils.mkdir(File.("~/.rpw/")) end FileUtils.touch(File.("~/.rpw/" + DOTFILE_NAME)) end |
.create_in_pwd! ⇒ Object
28 29 30 |
# File 'lib/rpw/client_data.rb', line 28 def self.create_in_pwd! FileUtils.touch(File.("./" + DOTFILE_NAME)) end |
.delete_filestore ⇒ Object
40 41 42 43 |
# File 'lib/rpw/client_data.rb', line 40 def self.delete_filestore return unless File.exist?(filestore_location) FileUtils.remove(filestore_location) end |
.exists? ⇒ Boolean
45 46 47 |
# File 'lib/rpw/client_data.rb', line 45 def self.exists? File.exist? filestore_location end |
.filestore_location ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/rpw/client_data.rb', line 49 def self.filestore_location if File.exist?(File.("./" + DOTFILE_NAME)) File.("./" + DOTFILE_NAME) else File.("~/.rpw/" + DOTFILE_NAME) end end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/rpw/client_data.rb', line 12 def [](key) data[key] end |
#[]=(key, value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rpw/client_data.rb', line 16 def []=(key, value) data data[key] = value begin File.write(filestore_location, YAML.dump(data)) rescue # raise Error, "The RPW data at #{filestore_location} is not writable. \ # Check your file permissions." end end |