Class: RPW::ClientData

Inherits:
Object
  • Object
show all
Defined in:
lib/rpw/client_data.rb

Constant Summary collapse

DOTFILE_NAME =
".rpw_info"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClientData

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.expand_path("~/.rpw/"))
    FileUtils.mkdir(File.expand_path("~/.rpw/"))
  end

  FileUtils.touch(File.expand_path("~/.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.expand_path("./" + DOTFILE_NAME))
end

.delete_filestoreObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/rpw/client_data.rb', line 45

def self.exists?
  File.exist? filestore_location
end

.filestore_locationObject



49
50
51
52
53
54
55
# File 'lib/rpw/client_data.rb', line 49

def self.filestore_location
  if File.exist?(File.expand_path("./" + DOTFILE_NAME))
    File.expand_path("./" + DOTFILE_NAME)
  else
    File.expand_path("~/.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