Class: Gyaazle::Config
- Inherits:
-
Object
- Object
- Gyaazle::Config
- Defined in:
- lib/gyaazle/config.rb
Constant Summary collapse
- CLIENT_ID =
"810975313441.apps.googleusercontent.com"- CLIENT_SECRET =
"0CJJ4jT2jcUsCWDrsHvXmARs"
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
-
#initialize(file = nil) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #save(json) ⇒ Object
- #update(values) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 |
# File 'lib/gyaazle/config.rb', line 8 def initialize(file = nil) @id = CLIENT_ID @secret = CLIENT_SECRET @file = file dir = File.dirname(@file) FileUtils.mkdir_p(dir) unless File.directory?(dir) FileUtils.touch(file) unless File.exists?(file) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/gyaazle/config.rb', line 6 def file @file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/gyaazle/config.rb', line 6 def id @id end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
6 7 8 |
# File 'lib/gyaazle/config.rb', line 6 def secret @secret end |
Instance Method Details
#load ⇒ Object
27 28 29 |
# File 'lib/gyaazle/config.rb', line 27 def load MultiJson.load(File.read(file), :symbolize_keys => true) rescue nil end |
#save(json) ⇒ Object
17 18 19 20 21 |
# File 'lib/gyaazle/config.rb', line 17 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
23 24 25 |
# File 'lib/gyaazle/config.rb', line 23 def update(values) save self.load.merge(values) end |