class WechatGate::Config

Attributes

app_name[R]
config[R]
output_type[R]

Public Class Methods

new(app_name, config_file = nil) { |self| ... } click to toggle source
# File lib/wechat_gate/config.rb, line 32
def initialize app_name, config_file = nil
  unless config_file
    if defined?(Rails)
      config_file = "#{Rails.root}/config/wechat.yml"
    end
  end

  raise Exception::ConfigException, "no wechat configuration file found!" unless config_file
  unless File.exists?(config_file)
    raise Exception::ConfigException, "configuration file does not exist!"
  end

  config_text = ERB.new(File.read(config_file)).result
  configs = YAML.load(config_text)
  unless configs[app_name]
    raise Exception::ConfigException, "no configuration found for app: #{app_name}!"
  end

  @config = if defined?(Rails)
    configs[app_name][Rails.env] || configs[app_name]
  else
    configs[app_name]
  end

  @app_name = app_name

  yield(self) if block_given?
end