Class: YoutubeSearcher::Config
- Inherits:
-
Object
- Object
- YoutubeSearcher::Config
- Includes:
- Singleton
- Defined in:
- lib/youtube-searcher/config.rb
Constant Summary collapse
- CONFIG_FILE =
".ytsrc"
Instance Method Summary collapse
- #config ⇒ Object (also: #get)
- #generate ⇒ Object
- #raw ⇒ Object
Instance Method Details
#config ⇒ Object Also known as: get
10 11 12 |
# File 'lib/youtube-searcher/config.rb', line 10 def config @config ||= Psych.load(raw).inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo } end |
#generate ⇒ Object
15 16 17 18 19 20 |
# File 'lib/youtube-searcher/config.rb', line 15 def generate default_config = raw.gsub(/download_directory.*\n/, "download_directory: \"#{ENV["HOME"]}\"\n") File.open(File.join(ENV["HOME"], ".ytsrc"), "w") do |f| f.puts default_config end end |
#raw ⇒ Object
22 23 24 |
# File 'lib/youtube-searcher/config.rb', line 22 def raw @raw ||= ERB.new(File.read(config_file)).result end |