Class: Pingfm::Config

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

Constant Summary collapse

CONFIG_PATH =
(RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'])
CONFIG_FILE =
File.expand_path(File.join(CONFIG_PATH, '.pingfm.yml'))

Class Method Summary collapse

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

.ask_for_app_key!Object

Prompts the user for their API key and saves it.



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

def ask_for_app_key!
  STDOUT.print 'Enter your Ping.fm User API key (http://ping.fm/key/): '
  @@config ||= {}
  @@config['app_key'] = STDIN.gets.chomp
  save!
end

.save!Object



23
24
25
26
27
# File 'lib/pingfm/config.rb', line 23

def save!
  ::File.open(CONFIG_FILE, 'w') do |config_file|
    ::YAML.dump(@@config, config_file)
  end
end

.setup!(config_file = CONFIG_FILE) ⇒ Object



29
30
31
32
# File 'lib/pingfm/config.rb', line 29

def setup!(config_file = CONFIG_FILE)
  raise Pingfm::ConfigNotFound unless File.exists?(config_file)
  @@config = ::YAML.load_file(config_file)
end