Module: MustBeOrdered::Notifier

Defined in:
lib/must_be_ordered/notifier.rb

Class Method Summary collapse

Class Method Details

.customized_logger=(active) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/must_be_ordered/notifier.rb', line 9

def customized_logger=(active)
  return unless active
  require 'fileutils'
  require 'logger'
  root_path = (defined?(::Rails) ? Rails.root.to_s : Dir.pwd).to_s
  FileUtils.mkdir_p(root_path + '/log')
  must_be_ordered_log_file = File.open("#{root_path}/log/must_be_ordered.log", 'a+')
  must_be_ordered_log_file.sync = true
  @customized_logger = Logger.new(must_be_ordered_log_file)
  def @customized_logger.format_message(severity, timestamp, _progname, msg)
    "#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
  end
end

.exception_class=(should_raise) ⇒ Object



5
6
7
# File 'lib/must_be_ordered/notifier.rb', line 5

def exception_class=(should_raise)
  @exception_class = (should_raise ? MustBeOrdered::OrderNotApplied : nil)
end

.format_message(severity, timestamp, _progname, msg) ⇒ Object



18
19
20
# File 'lib/must_be_ordered/notifier.rb', line 18

def @customized_logger.format_message(severity, timestamp, _progname, msg)
  "#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}[#{severity}] #{msg}"
end

.notify(message) ⇒ Object

Raises:

  • (@exception_class)


27
28
29
30
31
# File 'lib/must_be_ordered/notifier.rb', line 27

def notify(message)
  @customized_logger.warn(message) if @customized_logger
  Rails.logger.warn(message) if @rails_logger
  raise @exception_class, message if @exception_class
end

.rails_logger=(active) ⇒ Object



23
24
25
# File 'lib/must_be_ordered/notifier.rb', line 23

def rails_logger=(active)
  @rails_logger = active
end