Module: Scrapescrobbler::Config
Constant Summary collapse
- PATH =
ENV['SCRAPESCROBBLER_CONFIG_FILE'] || File.join(ENV['HOME'], '.scrapescrobbler.yml')
Instance Method Summary collapse
- #[](key) ⇒ Object
- #configure! ⇒ Object
-
#defaults ⇒ Object
Application defaults.
- #update!(values) ⇒ Object
Instance Method Details
#[](key) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/scrapescrobbler/config.rb', line 22 def [](key) overrides = File.exist?(PATH) ? YAML.load(File.read(PATH)) : {} defaults.merge(overrides)[key] rescue => e puts "invalid config file" puts e. defaults[key] end |
#configure! ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/scrapescrobbler/config.rb', line 31 def configure! unless File.exist?(PATH) File.open(PATH, 'w') do |fh| fh.puts(defaults.to_yaml) end end end |
#defaults ⇒ Object
Application defaults.
These are written to a config file by invoking: t configure
12 13 14 15 16 17 18 19 20 |
# File 'lib/scrapescrobbler/config.rb', line 12 def defaults { # Path to the sqlite db 'database_file' => "#{ENV['HOME']}/.scrapescrobbler.db", 'api_key' => "73af75e07cd58bfe66d13af9371b9504", 'api_secret' => "85b1b415e9c2b653e84bd1304d4dd9fa", 'token' => nil } end |
#update!(values) ⇒ Object
39 40 41 42 43 |
# File 'lib/scrapescrobbler/config.rb', line 39 def update! values File.open(PATH, 'w') do |fh| fh.puts(defaults.update(values).to_yaml) end end |