Class: Gigawatt::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/gigawatt/settings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Settings

Returns a new instance of Settings.



5
6
7
8
# File 'lib/gigawatt/settings.rb', line 5

def initialize(options = {})
  @options = Settings.defaults.merge(options)
  read if setup?
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



3
4
5
# File 'lib/gigawatt/settings.rb', line 3

def access_key
  @access_key
end

#companiesObject

Returns the value of attribute companies.



3
4
5
# File 'lib/gigawatt/settings.rb', line 3

def companies
  @companies
end

#projectsObject

Returns the value of attribute projects.



3
4
5
# File 'lib/gigawatt/settings.rb', line 3

def projects
  @projects
end

#staffObject

Returns the value of attribute staff.



3
4
5
# File 'lib/gigawatt/settings.rb', line 3

def staff
  @staff
end

Class Method Details

.defaultsObject



10
11
12
13
14
# File 'lib/gigawatt/settings.rb', line 10

def self.defaults
  {
    :path => File.join(Dir.home, '.88miles')
  }
end

Instance Method Details

#pathObject



20
21
22
# File 'lib/gigawatt/settings.rb', line 20

def path
  @options[:path]
end

#readObject



24
25
26
27
28
29
# File 'lib/gigawatt/settings.rb', line 24

def read
  self.access_key = YAML.load_file(File.join(path, 'accesskey')) if File.exists?(File.join(path, 'accesskey'))
  self.companies = YAML.load_file(File.join(path, 'companies')) if File.exists?(File.join(path, 'companies'))
  self.projects = YAML.load_file(File.join(path, 'projects')) if File.exists?(File.join(path, 'projects'))
  self.staff = YAML.load_file(File.join(path, 'staff')) if File.exists?(File.join(path, 'staff'))
end

#setup?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gigawatt/settings.rb', line 16

def setup?
  File.exists?(path) && File.directory?(path)
end

#write(type) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/gigawatt/settings.rb', line 31

def write(type)
  # Make the directory if it doesn't exist
  FileUtils.mkdir_p(path) unless File.exists?(path)
  File.write(File.join(path, 'accesskey'), self.access_key.to_yaml) if type == :accesskey
  File.write(File.join(path, 'companies'), self.companies.to_yaml) if type == :companies
  File.write(File.join(path, 'projects'), self.projects.to_yaml) if type == :projects
  File.write(File.join(path, 'staff'), self.staff.to_yaml) if type == :staff
  FileUtils.chmod 0700, path
end