Class: Twibot::FileConfig

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

Overview

Configuration from files

Constant Summary

Constants inherited from Config

Config::DEFAULT

Instance Attribute Summary

Attributes inherited from Config

#settings

Instance Method Summary collapse

Methods inherited from Config

#add, default, #method_missing, #to_hash

Constructor Details

#initialize(fos = File.expand_path("config/bot.yml")) ⇒ FileConfig

Accepts a stream or a file to read configuration from Default is to read configuration from ./config/bot.yml

If a stream is passed it is not closed from within the method



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/twibot/config.rb', line 123

def initialize(fos = File.expand_path("config/bot.yml"))
  stream = fos.is_a?(String) ? File.open(fos, "r") : fos

  begin
    config = YAML.load(stream.read)
    config.symbolize_keys! if config
  rescue Exception => err
    puts err.message
    puts "Unable to load configuration, aborting"
    exit
  ensure
    stream.close if fos.is_a?(String)
  end

  super config.is_a?(Hash) ? config : {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Twibot::Config