Module: SyncUtil
- Defined in:
- lib/transync/sync/sync_util.rb
Class Method Summary collapse
- .build_diff_print(diff, msg, diff_only = nil) ⇒ Object
- .create_logger(direction) ⇒ Object
- .info_clean(file, language, message) ⇒ Object
- .info_diff(file, language, diff, diff_only = nil) ⇒ Object
- .log_and_puts(msg) ⇒ Object
Class Method Details
.build_diff_print(diff, msg, diff_only = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/transync/sync/sync_util.rb', line 21 def self.build_diff_print(diff, msg, diff_only = nil) begin # get longest key and value max_key_length = diff.keys.max { |a, b| a.length <=> b.length }.length max_val_length = diff.values.max { |a, b| a[1].to_s.length <=> b[1].to_s.length }[1].length rescue max_key_length = 0 max_val_length = 0 end newline = '' diff.keys.each do |key| change_mark = ' => ' operation = diff[key][1].nil? ? 'adding' : 'changing' ljust = 8 if diff_only operation = 'diff' change_mark = ' <=> ' ljust = 4 end msg += "#{newline}[#{operation.ljust(ljust)}] #{key.ljust(max_key_length)}: '#{diff[key][1].to_s.ljust(max_val_length)}'#{change_mark}'#{diff[key][0]}' " newline = "\n" end msg end |
.create_logger(direction) ⇒ Object
54 55 56 |
# File 'lib/transync/sync/sync_util.rb', line 54 def self.create_logger(direction) @logger = Logger.new(".transync_log/#{direction}.log", 'monthly') end |
.info_clean(file, language, message) ⇒ Object
6 7 8 9 |
# File 'lib/transync/sync/sync_util.rb', line 6 def self.info_clean(file, language, ) msg = "#{file} (#{language}) - #{}" SyncUtil.log_and_puts(msg) end |
.info_diff(file, language, diff, diff_only = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/transync/sync/sync_util.rb', line 11 def self.info_diff(file, language, diff, diff_only = nil) msg = '' unless diff.empty? msg = "#{file} (#{language})\n" if not diff_only msg = build_diff_print(diff, msg, diff_only) end SyncUtil.log_and_puts(msg) end |
.log_and_puts(msg) ⇒ Object
49 50 51 52 |
# File 'lib/transync/sync/sync_util.rb', line 49 def self.log_and_puts(msg) puts msg unless msg.length == 0 @logger.info msg end |