Class: Pingfm::Config
- Inherits:
-
Object
- Object
- Pingfm::Config
- Defined in:
- lib/pingfm/config.rb
Constant Summary collapse
- CONFIG_PATH =
(RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'])
- CONFIG_FILE =
File.(File.join(CONFIG_PATH, '.pingfm.yml'))
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
-
.ask_for_app_key! ⇒ Object
Prompts the user for their API key and saves it.
- .save! ⇒ Object
- .setup!(config_file = CONFIG_FILE) ⇒ Object
Class Method Details
.[](key) ⇒ Object
18 19 20 21 |
# File 'lib/pingfm/config.rb', line 18 def [](key) setup! unless defined?(@@config) @@config[key] end |
.[]=(key, value) ⇒ Object
23 24 25 26 27 |
# File 'lib/pingfm/config.rb', line 23 def []=(key, value) @@config ||= {} @@config[key] = value save! end |
.ask_for_app_key! ⇒ Object
Prompts the user for their API key and saves it.
13 14 15 16 |
# File 'lib/pingfm/config.rb', line 13 def ask_for_app_key! STDOUT.print 'Enter your Ping.fm User API key (http://ping.fm/key/): ' STDIN.gets.chomp end |
.save! ⇒ Object
29 30 31 32 33 |
# File 'lib/pingfm/config.rb', line 29 def save! ::File.open(CONFIG_FILE, 'w') do |config_file| ::YAML.dump(@@config, config_file) end end |
.setup!(config_file = CONFIG_FILE) ⇒ Object
35 36 37 38 |
# File 'lib/pingfm/config.rb', line 35 def setup!(config_file = CONFIG_FILE) raise Pingfm::ConfigNotFound unless File.exists?(config_file) @@config = ::YAML.load_file(config_file) end |