Class: DriveEnv::Config
- Inherits:
-
Object
- Object
- DriveEnv::Config
- Defined in:
- lib/drive_env/config.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
File.('~/.config/drive_env/config')
- DEFAULT_TOKENS_STORE_FILE =
File.('~/.config/drive_env/tokens.yml')
- DEFAULT_TOKEN_USER_ID =
'default'
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #lookup_spreadsheet_url_by_alias(name) ⇒ Object
- #migrate ⇒ Object
- #save ⇒ Object
- #set_alias_for_spreadsheet(name, url) ⇒ Object
- #unset_alias_for_spreadsheet(name) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 |
# File 'lib/drive_env/config.rb', line 13 def initialize @spreadsheet_aliases = {} @config_file = DEFAULT_CONFIG_FILE end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/drive_env/config.rb', line 10 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
11 12 13 |
# File 'lib/drive_env/config.rb', line 11 def client_secret @client_secret end |
Class Method Details
.load(file) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/drive_env/config.rb', line 51 def load(file) obj = File.exist?(file) ? YAML.load(File.read(file)) : self.new obj.instance_variable_set("@config_file", file) obj.migrate obj end |
Instance Method Details
#lookup_spreadsheet_url_by_alias(name) ⇒ Object
26 27 28 |
# File 'lib/drive_env/config.rb', line 26 def lookup_spreadsheet_url_by_alias(name) @spreadsheet_aliases[name] end |
#migrate ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/drive_env/config.rb', line 41 def migrate ## dropped variables in 0.2.pre1 %W[access_token refresh_token expires_at].each do |v| if instance_variable_get("@#{v}") remove_instance_variable("@#{v}") end end end |
#save ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/drive_env/config.rb', line 30 def save dir = File.dirname(@config_file) if !File.directory?(dir) FileUtils.mkdir_p(dir) end File.open(@config_file, 'w') do |fh| fh << YAML.dump(self) end end |
#set_alias_for_spreadsheet(name, url) ⇒ Object
18 19 20 |
# File 'lib/drive_env/config.rb', line 18 def set_alias_for_spreadsheet(name, url) @spreadsheet_aliases[name] = url end |
#unset_alias_for_spreadsheet(name) ⇒ Object
22 23 24 |
# File 'lib/drive_env/config.rb', line 22 def unset_alias_for_spreadsheet(name) @spreadsheet_aliases.delete(name) end |