Class: DevPKI::DataDirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/devpki/data_directory.rb

Class Method Summary collapse

Class Method Details

.absolute_pathObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/devpki/data_directory.rb', line 42

def self.absolute_path
  unexpanded = (case self.os
    when :linux
      File.join(XDG['DATA_HOME'].to_s, "devpki")
    when :macosx
      "~/Library/Application Support/devpki"
    else
      nil
  end)
  File.expand_path(unexpanded)
end

.absolute_path_for(file_name) ⇒ Object



54
55
56
# File 'lib/devpki/data_directory.rb', line 54

def self.absolute_path_for(file_name)
  File.expand_path(file_name, self.absolute_path)
end

.getObject



58
59
60
61
62
63
# File 'lib/devpki/data_directory.rb', line 58

def self.get
  if not Dir.exists?(self.absolute_path)
    Dir.mkdir(self.absolute_path)
  end
  Dir.new(self.absolute_path)
end

.osObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/devpki/data_directory.rb', line 14

def self.os
  @os ||= (
    host_os = RbConfig::CONFIG['host_os']
    case host_os
    when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
      :windows
    when /darwin|mac os/
      :macosx
    when /linux/
      :linux
    when /solaris|bsd/
      :unix
    else
      raise Error.new("unknown os: #{host_os.inspect}")
    end
  )
end

.platform_supported?Boolean

Only support OSX atm

Returns:

  • (Boolean)


33
34
35
# File 'lib/devpki/data_directory.rb', line 33

def self.platform_supported?
  return self.supported_operating_systems.include?(self.os)
end

.reset_to_emptyObject



37
38
39
40
# File 'lib/devpki/data_directory.rb', line 37

def self.reset_to_empty
  FileUtils.rm_rf(self.absolute_path)
  self.get
end

.supported_operating_systemsObject



10
11
12
# File 'lib/devpki/data_directory.rb', line 10

def self.supported_operating_systems
 [:linux, :macosx]
end