class MessengerPigeon::Config

MessengerPigeon Configuration

Attributes

conf[R]

Public Class Methods

new(config, pigeons = []) click to toggle source
# File lib/messenger_pigeon/config.rb, line 6
def initialize(config, pigeons = [])
  @conf = {}
  @pigeons = pigeons
  update config
end

Public Instance Methods

release_pigeon?(name) click to toggle source
# File lib/messenger_pigeon/config.rb, line 12
def release_pigeon?(name)
  @pigeons.empty? || @pigeons.include?(name)
end

Private Instance Methods

apply_config(config) click to toggle source

TODO: should do a whole lot more checking. Config pretty expressive and we want to catch problems ASAP.

# File lib/messenger_pigeon/config.rb, line 33
def apply_config(config)
  [:pigeon, :target, :source].each do |setting|
    fail "Configuration invalid: #{setting.to_s}" unless
      config[setting] && config[setting].class == Hash &&
      !config[setting].keys.empty?
  end
  @conf = config
end
load_file(config) click to toggle source
# File lib/messenger_pigeon/config.rb, line 42
def load_file(config)
  binding.eval(File.read(File.expand_path(config)))
end
update(new_conf) click to toggle source
# File lib/messenger_pigeon/config.rb, line 18
def update(new_conf)
  temp_conf = @conf.clone
  case new_conf
  when String
    temp_conf.merge!(load_file new_conf)
  when Hash
    temp_conf.merge! new_conf
  else
    fail "Unsupported configuration datatype: #{new_conf.class}"
  end
  apply_config temp_conf
end