Class: GoogleDrive::Config

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

Overview

:nodoc:

Constant Summary collapse

FIELDS =
%w(client_id client_secret scope refresh_token).freeze

Instance Method Summary collapse

Constructor Details

#initialize(config_path) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
# File 'lib/google_drive/config.rb', line 11

def initialize(config_path)
  @config_path = config_path
  if ::File.exist?(config_path)
    JSON.parse(::File.read(config_path)).each do |key, value|
      instance_variable_set("@#{key}", value) if FIELDS.include?(key)
    end
  end
end

Instance Method Details

#saveObject



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

def save
  ::File.open(@config_path, 'w', 0600) { |f| f.write(to_json) }
end