alexyoung / captor

A GUI for Capistrano

This URL has Read+Write access

captor / config.rb
100644 44 lines (37 sloc) 1.112 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'yaml'
 
class Settings
  def self.app_name=(app_name)
    @@app_name = app_name
  end
 
  def self.data_path(data_file_name = 'data.yml')
    if RUBY_PLATFORM =~ /win32/
      if ENV['USERPROFILE']
        if File.exist?(File.join(File.expand_path(ENV['USERPROFILE']), "Application Data"))
          user_data_directory = File.join File.expand_path(ENV['USERPROFILE']), "Application Data", @@app_name
        else
          user_data_directory = File.join File.expand_path(ENV['USERPROFILE']), @@app_name
        end
      else
        user_data_directory = File.join File.expand_path(Dir.getwd), 'data'
      end
    else
      user_data_directory = File.expand_path(File.join("~", ".#{@@app_name}"))
    end
    
    unless File.exist?(user_data_directory)
      Dir.mkdir(user_data_directory)
    end
    
    return File.join(user_data_directory, data_file_name)
  end
 
  def self.load
    if File.exist?(data_path)
      YAML::load(File.open(data_path, 'r'))
    else
      []
    end
  end
  
  
  def self.save(data)
    File.open(data_path, 'w') do |f|
      f.write data.to_yaml
    end
  end
end