Class: Cartoset::Config
- Inherits:
-
Object
- Object
- Cartoset::Config
- Defined in:
- lib/cartoset/config.rb
Constant Summary collapse
- CARTODB_DEFAULT_HOST =
'https://api.cartodb.com'
- @@path =
Rails.root.join(config_env_folder, 'cartoset_config.yml')
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .cartodb_settings? ⇒ Boolean
- .consolidate_settings ⇒ Object
- .destroy ⇒ Object
- .empty ⇒ Object
- .local_postgis_settings? ⇒ Boolean
- .set_cartodb_credentials(user) ⇒ Object
- .settings ⇒ Object
- .settings=(values) ⇒ Object
- .setup_cartodb ⇒ Object
- .update(values) ⇒ Object
- .valid? ⇒ Boolean
- .valid_user?(user) ⇒ Boolean
Class Method Details
.[](key) ⇒ Object
50 51 52 |
# File 'lib/cartoset/config.rb', line 50 def [](key) settings[key] end |
.[]=(key, value) ⇒ Object
54 55 56 |
# File 'lib/cartoset/config.rb', line 54 def []=(key, value) settings[key] = value end |
.cartodb_settings? ⇒ Boolean
32 33 34 |
# File 'lib/cartoset/config.rb', line 32 def cartodb_settings? settings['cartodb_oauth_key'].present? && settings['cartodb_oauth_secret'].present? && settings['cartodb_oauth_access_token'].present? && settings['cartodb_oauth_access_token_secret'].present? end |
.consolidate_settings ⇒ Object
96 97 98 99 100 101 |
# File 'lib/cartoset/config.rb', line 96 def consolidate_settings File.open(path, "w") do |f| f.write(settings.to_yaml) end rescue end |
.destroy ⇒ Object
58 59 60 |
# File 'lib/cartoset/config.rb', line 58 def destroy FileUtils.rm_f(path) if File.exists?(path) end |
.empty ⇒ Object
23 24 25 26 |
# File 'lib/cartoset/config.rb', line 23 def empty settings = {} consolidate_settings end |
.local_postgis_settings? ⇒ Boolean
37 38 39 |
# File 'lib/cartoset/config.rb', line 37 def local_postgis_settings? settings['host'].present? && settings['port'].present? && settings['user'].present? && settings['password'].present? && settings['database'].present? end |
.set_cartodb_credentials(user) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cartoset/config.rb', line 42 def set_cartodb_credentials(user) update :cartodb_user_uid => user.uid, :cartodb_oauth_access_token => user.credentials['token'], :cartodb_oauth_access_token_secret => user.credentials['secret'] setup_cartodb end |
.settings ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/cartoset/config.rb', line 87 def settings @@settings ||= begin hash = (YAML.load_file(path) || {}) hash = hash.merge(Hash[ENV].slice(hash.keys)) rescue Exception => e {} end end |
.settings=(values) ⇒ Object
82 83 84 |
# File 'lib/cartoset/config.rb', line 82 def settings=(values) @@settings = values end |
.setup_cartodb ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cartoset/config.rb', line 62 def setup_cartodb if settings['cartodb_oauth_key'].present? && settings['cartodb_oauth_secret'].present? cartodb_settings = { 'host' => settings['cartodb_host'] || CARTODB_DEFAULT_HOST, 'oauth_key' => settings['cartodb_oauth_key'], 'oauth_secret' => settings['cartodb_oauth_secret'], 'oauth_access_token' => settings['cartodb_oauth_access_token'], 'oauth_access_token_secret' => settings['cartodb_oauth_access_token_secret'] } CartoDB::Init.start cartodb_settings end end |
.update(values) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cartoset/config.rb', line 13 def update(values) return if values.nil? values.each do |key, value| value = value.add_https_if_required! if key.to_sym == :cartodb_host @@settings[key.to_s] = value end consolidate_settings end |
.valid? ⇒ Boolean
28 29 30 |
# File 'lib/cartoset/config.rb', line 28 def valid? settings.present? && (cartodb_settings? || local_postgis_settings?) && settings['app_name'].present? && settings['features_table'].present? end |
.valid_user?(user) ⇒ Boolean
78 79 80 |
# File 'lib/cartoset/config.rb', line 78 def valid_user?(user) user.present? && user.uid.eql?(settings['cartodb_user_uid']) end |