Module: ArMailerRevised::Helpers::General

Included in:
Mailman
Defined in:
lib/ar_mailer_revised/helpers/general.rb

Instance Method Summary collapse

Instance Method Details

#log_fileString

TODO:

Check if that interferes with Rails’ logging process

Determines the correct log file location It defaults to the current environment’s log file

Returns:

  • (String)

    Path to the logfile



47
48
49
# File 'lib/ar_mailer_revised/helpers/general.rb', line 47

def log_file
  @log_file ||= @options[:log_file] ? File.expand_path(@options[:log_file]) : File.join(Rails.root, 'log', "#{rails_environment}.log")
end

#log_levelInt

Determines the correct log level from the given script arguments Defaults to INFO

Returns:

  • (Int)

    a log level from Log4r



57
58
59
# File 'lib/ar_mailer_revised/helpers/general.rb', line 57

def log_level
  @log_level ||= "Log4r::#{@options[:log_level].upcase}".constantize
end

#loggerLog4r::Logger

Generates a logger object using Log4r The output file is determined by #log_file

If the custom log file path is set to stdout or stderr, these are used instead of a log file.

Returns:

  • (Log4r::Logger)

    the file output logger



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ar_mailer_revised/helpers/general.rb', line 22

def logger
  unless @logger
    @logger            = Log4r::Logger.new 'ar_mailer'

    if %w[stdout stderr].include?(@options[:log_file])
      outputter = Log4r::Outputter.send(@options[:log_file])
    else
      outputter = Log4r::FileOutputter.new('ar_mailer_log', :filename => log_file)
    end

    outputter.formatter = Log4r::PatternFormatter.new(:pattern => '[%5l - %c] %d :: %m')
    @logger.outputters = outputter

    @logger.level      = log_level
  end
  @logger
end

#rails_environmentString

Returns the currently active rails environment.

Returns:

  • (String)

    the currently active rails environment



64
65
66
# File 'lib/ar_mailer_revised/helpers/general.rb', line 64

def rails_environment
  ENV['RAILS_ENV']
end

#rails_environment?(env) ⇒ Bool

Checks if the given environment is currently active Works like Rails.env.env?

Parameters:

  • env (String, Symbol)

    The environment name

Returns:

  • (Bool)

    true if the current environment matches the given



76
77
78
# File 'lib/ar_mailer_revised/helpers/general.rb', line 76

def rails_environment?(env)
  rails_environment.to_s == env.to_s
end