Class: HackathonDrone::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/hackathon_drone/configuration.rb

Constant Summary collapse

CONFIG_FILE =
File.expand_path('~/.hackathon_drone')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Configuration

—– Configuration file management —–



12
13
14
15
16
# File 'lib/hackathon_drone/configuration.rb', line 12

def initialize(project)
  @project = project
  @config = File.exists?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : {}
  @config[@project] ||= {}
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



9
10
11
# File 'lib/hackathon_drone/configuration.rb', line 9

def project
  @project
end

Instance Method Details

#get(key) ⇒ Object



27
28
29
# File 'lib/hackathon_drone/configuration.rb', line 27

def get(key)
  @config[@project][key]
end

#resetObject



18
19
20
21
# File 'lib/hackathon_drone/configuration.rb', line 18

def reset
  @config.delete(@project)
  save
end

#saveObject



23
24
25
# File 'lib/hackathon_drone/configuration.rb', line 23

def save
  File.open(CONFIG_FILE, 'w+') {|f| f.write(@config.to_yaml) }
end

#set(key, value) ⇒ Object



31
32
33
34
35
# File 'lib/hackathon_drone/configuration.rb', line 31

def set(key, value)
  @config[@project][key] = value
  save
  value
end