module MailCannon
Refinements over stdlib to avoid depending on ActiveSupport and friends.
Keeps the versioning clean and simple.
Public Class Methods
config(root_dir=nil)
click to toggle source
Returns the config Hash
# File lib/mailcannon.rb, line 39 def self.config(root_dir=nil) @config ||= load_config(root_dir) end
initialize_logger(log_target = STDOUT)
click to toggle source
Initializes logger with mailcannon setup
# File lib/mailcannon.rb, line 66 def self.initialize_logger(log_target = STDOUT) oldlogger = @logger @logger = Logger.new(log_target) @logger.level = Logger::INFO @logger.progname = 'mailcannon' oldlogger.close if oldlogger && !$TESTING # don't want to close testing's STDOUT logging @logger end
load_config(root_dir=nil)
click to toggle source
Loads the config Hash from the YAML
# File lib/mailcannon.rb, line 44 def self.load_config(root_dir=nil) root_dir ||= Pathname.new(Dir.pwd) path = "#{root_dir}/config/mailcannon.yml" raise "Couldn't find config yml at #{path}." unless File.file?(path) content = File.read(path) erb = ERB.new(content).result YAML.load(erb) end
logger()
click to toggle source
Returns the lib logger object
# File lib/mailcannon.rb, line 61 def self.logger @logger || initialize_logger end
warmode()
click to toggle source
To be used with caution
# File lib/mailcannon.rb, line 30 def self.warmode #Mongoid.load!("config/mongoid.yml", ENV['RACK_ENV']||'development') # change to env URL Sidekiq.configure_client do |config| config.redis = { :namespace => 'mailcannon', :size => 1, :url => ENV['REDIS_URL'] } end end
Public Instance Methods
deep_merge(other_hash, &block)
click to toggle source
# File lib/mailcannon/hash.rb, line 12 def deep_merge(other_hash, &block) dup.deep_merge!(other_hash, &block) end
deep_merge!(other_hash, &block)
click to toggle source
Same as deep_merge
, but modifies self
.
# File lib/mailcannon/hash.rb, line 17 def deep_merge!(other_hash, &block) other_hash.each_pair do |k,v| tv = self[k] if tv.is_a?(Hash) && v.is_a?(Hash) self[k] = tv.deep_merge(v, &block) else self[k] = block && tv ? block.call(k, tv, v) : v end end self end
logger()
click to toggle source
alias method
# File lib/mailcannon.rb, line 56 def logger MailCannon.logger end
symbolize_keys!()
click to toggle source
# File lib/mailcannon/hash.rb, line 4 def symbolize_keys! keys.each do |key| self[(key.to_sym rescue key) || key] = delete(key) end self end