Class: Arrival::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/arrival/logger.rb

Overview

Copies the ActiveRecord::Migration #say and #write plus a new #write_no_newline to log the migration’s status. It’s not possible to reuse the from ActiveRecord::Migration because the migration’s instance can’t be seen from the connection adapter.

Instance Method Summary collapse

Constructor Details

#initialize(sanitizers) ⇒ Logger

Returns a new instance of Logger.



7
8
9
# File 'lib/arrival/logger.rb', line 7

def initialize(sanitizers)
  @sanitizers = sanitizers
end

Instance Method Details

#say(message, subitem = false) ⇒ Object

Outputs the message through the stdout, following the ActiveRecord::Migration log format

Parameters:

  • message (String)
  • subitem (Boolean) (defaults to: false)

    whether to show message as a nested log item



16
17
18
# File 'lib/arrival/logger.rb', line 16

def say(message, subitem = false)
  write "#{subitem ? '   ->' : '--'} #{message}"
end

#write(text = '') ⇒ Object

Outputs the text through the stdout adding a new line at the end

Parameters:

  • text (String) (defaults to: '')


23
24
25
# File 'lib/arrival/logger.rb', line 23

def write(text = '')
  puts(sanitize(text))
end

#write_no_newline(text) ⇒ Object

Outputs the text through the stdout without adding a new line at the end

Parameters:

  • text (String)


30
31
32
# File 'lib/arrival/logger.rb', line 30

def write_no_newline(text)
  print(sanitize(text))
end