Class: Snipe::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/snipe/logic/config.rb

Constant Summary collapse

FILE =
File.expand_path("~/.snipe")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/snipe/logic/config.rb', line 8

def api_key
  @api_key
end

#domainObject

Returns the value of attribute domain.



9
10
11
# File 'lib/snipe/logic/config.rb', line 9

def domain
  @domain
end

#fromObject

Returns the value of attribute from.



10
11
12
# File 'lib/snipe/logic/config.rb', line 10

def from
  @from
end

Class Method Details

.exists?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/snipe/logic/config.rb', line 12

def self.exists?
  File.exists?(FILE)
end

Instance Method Details

#loadObject



16
17
18
19
20
21
22
23
# File 'lib/snipe/logic/config.rb', line 16

def load
  yaml = File.read(FILE)
  loaded = Psych.load(yaml)

  @api_key = loaded["api_key"]
  @domain = loaded["domain"]
  @from = loaded["from"]
end

#saveObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/snipe/logic/config.rb', line 25

def save
  to_save = {
    "api_key" => @api_key,
    "domain" => @domain,
    "from" => @from
  }

  yaml = Psych.dump(to_save)
  File.write(FILE, yaml)
end