Class: Ugc::Settings
- Inherits:
-
Object
- Object
- Ugc::Settings
- Defined in:
- lib/ugc/settings.rb
Constant Summary collapse
- SETTINGS_FILE =
'settings.yml'
Instance Method Summary collapse
- #access_token ⇒ Object
- #access_token=(token) ⇒ Object
- #active_profile_name ⇒ Object
- #active_profile_name=(name) ⇒ Object
- #application ⇒ Object
- #application=(app) ⇒ Object
- #base_url ⇒ Object
- #base_url=(url) ⇒ Object
- #configured? ⇒ Boolean
- #delete_profile(name) ⇒ Object
-
#initialize(global_options) ⇒ Settings
constructor
A new instance of Settings.
- #load_profile_blob(name) ⇒ Object
- #logged_in? ⇒ Boolean
- #organization ⇒ Object
- #organization=(org) ⇒ Object
- #profile(name = nil) ⇒ Object
- #profiles ⇒ Object
- #save_profile_blob(name, data) ⇒ Object
- #show_curl? ⇒ Boolean
- #table_border? ⇒ Boolean
Constructor Details
#initialize(global_options) ⇒ Settings
Returns a new instance of Settings.
6 7 8 9 10 11 |
# File 'lib/ugc/settings.rb', line 6 def initialize() @draw_table_border = [:border] @show_curl = [:curl] @settings_file = File.join [:settings], SETTINGS_FILE @settings = YAML.load_file(@settings_file) rescue default_settings end |
Instance Method Details
#access_token ⇒ Object
64 65 66 |
# File 'lib/ugc/settings.rb', line 64 def access_token profile['access_token'] end |
#access_token=(token) ⇒ Object
68 69 70 |
# File 'lib/ugc/settings.rb', line 68 def access_token=(token) set_profile 'access_token', token end |
#active_profile_name ⇒ Object
13 14 15 |
# File 'lib/ugc/settings.rb', line 13 def active_profile_name @settings['active_profile'] || 'local' end |
#active_profile_name=(name) ⇒ Object
17 18 19 20 21 |
# File 'lib/ugc/settings.rb', line 17 def active_profile_name=(name) raise "unknown profile: #{name}" unless profile(name) @settings['active_profile'] = name save_profile end |
#application ⇒ Object
56 57 58 |
# File 'lib/ugc/settings.rb', line 56 def application profile['application'] end |
#application=(app) ⇒ Object
60 61 62 |
# File 'lib/ugc/settings.rb', line 60 def application=(app) set_profile 'application', app end |
#base_url ⇒ Object
39 40 41 |
# File 'lib/ugc/settings.rb', line 39 def base_url profile['base_url'] end |
#base_url=(url) ⇒ Object
43 44 45 46 |
# File 'lib/ugc/settings.rb', line 43 def base_url=(url) URI.parse url set_profile 'base_url', url end |
#configured? ⇒ Boolean
72 73 74 |
# File 'lib/ugc/settings.rb', line 72 def configured? base_url && organization && application end |
#delete_profile(name) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ugc/settings.rb', line 23 def delete_profile(name) raise "cannot delete active profile" if active_profile_name == name raise "unknown profile: #{name}" unless profiles[name] profiles.delete name save_profile end |
#load_profile_blob(name) ⇒ Object
95 96 97 |
# File 'lib/ugc/settings.rb', line 95 def load_profile_blob(name) IO.read File.join settings_dir, "#{active_profile_name}.#{name}" end |
#logged_in? ⇒ Boolean
84 85 86 |
# File 'lib/ugc/settings.rb', line 84 def logged_in? !!access_token end |
#organization ⇒ Object
48 49 50 |
# File 'lib/ugc/settings.rb', line 48 def organization profile['organization'] end |
#organization=(org) ⇒ Object
52 53 54 |
# File 'lib/ugc/settings.rb', line 52 def organization=(org) set_profile 'organization', org end |
#profile(name = nil) ⇒ Object
30 31 32 33 |
# File 'lib/ugc/settings.rb', line 30 def profile(name=nil) name ||= active_profile_name profiles[name] || profiles[name] = {} end |
#profiles ⇒ Object
35 36 37 |
# File 'lib/ugc/settings.rb', line 35 def profiles @settings['profiles'] || @settings['profiles'] = {} end |
#save_profile_blob(name, data) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/ugc/settings.rb', line 88 def save_profile_blob(name, data) file = File.join settings_dir, "#{active_profile_name}.#{name}" File.open(file, 'w') do |out| out.write data end end |
#show_curl? ⇒ Boolean
80 81 82 |
# File 'lib/ugc/settings.rb', line 80 def show_curl? !!@show_curl end |
#table_border? ⇒ Boolean
76 77 78 |
# File 'lib/ugc/settings.rb', line 76 def table_border? !!@draw_table_border end |