module Feed2Email

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/feed2email.rb, line 8
def self.config
  @config ||= Config.new(config_path)
end
config_path() click to toggle source
# File lib/feed2email.rb, line 12
def self.config_path
  root.join('config.yml').to_s
end
database_path() click to toggle source
# File lib/feed2email.rb, line 16
def self.database_path
  root.join('feed2email.db').to_s
end
logger() click to toggle source
# File lib/feed2email.rb, line 20
def self.logger
  return @logger if @logger

  if config['log_path'] == true
    logdev = $stdout
  elsif config['log_path'] # truthy but not true (a path)
    logdev = File.expand_path(config['log_path'])
  end

  @logger = Logger.new(logdev, config['log_shift_age'],
                       config['log_shift_size'].megabytes)
  @logger.level = Logger.const_get(config['log_level'].upcase)
  @logger
end
root() click to toggle source
# File lib/feed2email.rb, line 59
def self.root
  @root ||= Pathname.new(ENV['HOME']).join('.feed2email')
end
setup_database() click to toggle source
# File lib/feed2email.rb, line 35
def self.setup_database
  @db ||= Database.new(
    adapter:       'sqlite',
    database:      database_path,
    loggers:       [logger],
    sql_log_level: :debug
  )
end
smtp_connection() click to toggle source
# File lib/feed2email.rb, line 44
def self.smtp_connection
  return @smtp if @smtp

  @smtp = Net::SMTP.new(config['smtp_host'], config['smtp_port'])
  @smtp.enable_starttls if config['smtp_starttls']
  @smtp.start('localhost',
    config['smtp_user'],
    config['smtp_pass'],
    config['smtp_auth'].to_sym
  )
  at_exit { @smtp.finish }

  @smtp
end