Class: Gyaazle::Config

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

Constant Summary collapse

CLIENT_ID =
"810975313441.apps.googleusercontent.com"
CLIENT_SECRET =
"0CJJ4jT2jcUsCWDrsHvXmARs"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
# File 'lib/gyaazle/config.rb', line 8

def initialize(file = nil)
  @id = CLIENT_ID
  @secret = CLIENT_SECRET
  @file = file
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/gyaazle/config.rb', line 6

def id
  @id
end

#secretObject (readonly)

Returns the value of attribute secret.



6
7
8
# File 'lib/gyaazle/config.rb', line 6

def secret
  @secret
end

Instance Method Details

#fileObject



28
29
30
31
32
33
# File 'lib/gyaazle/config.rb', line 28

def file
  dir = File.dirname(@file)
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
  FileUtils.touch(@file) unless File.exists?(@file)
  @file
end

#loadObject



24
25
26
# File 'lib/gyaazle/config.rb', line 24

def load
  MultiJson.load(File.read(file), :symbolize_keys => true) rescue nil
end

#save(json) ⇒ Object



14
15
16
17
18
# File 'lib/gyaazle/config.rb', line 14

def save(json)
  File.open(file, "w") do |f|
    f.write json.is_a?(String) ? json : MultiJson.dump(json, :pretty => true)
  end
end

#update(values) ⇒ Object



20
21
22
# File 'lib/gyaazle/config.rb', line 20

def update(values)
  save self.load.merge(values)
end