Class: Grouik::Helpers::Process

Inherits:
Object
  • Object
show all
Defined in:
src/lib/grouik/helpers/process.rb

Overview

Helper providing outputs (mostly useful in a CLI/Rake context)

Main methods are display_errors and display_status

Instance Method Summary collapse

Instance Method Details

#display_errors(process) ⇒ self

Display loading errors

Parameters:

Returns:

  • (self)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'src/lib/grouik/helpers/process.rb', line 17

def display_errors(process)
  process.errors.each do |_k, struct|
    Grouik.message do |m|
      m.stream  = STDERR
      m.type    = 'error'
      m.content = ('%s:%s: %s' % [
                     struct.source,
                     struct.line,
                     struct.message,
                   ])
    end
  end
end

#display_status(process) ⇒ self

Display (on STDERR) loader related statistics

Parameters:

Returns:

  • (self)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'src/lib/grouik/helpers/process.rb', line 35

def display_status(process)
  message  = '%s: %s files; %s iterations; %s errors (%.4f) [%s]'
  loader   = process.loader

  Grouik.message do |m|
    m.stream  = STDERR
    m.type    = 'status_%s' % status(process)
    m.content = (message %
                 [
                   status(process).to_s.capitalize,
                   loader.loadables.size,
                   loader.attempts,
                   loader.errors.size,
                   loader.stats ? loader.stats.real : 0,
                   format_filepath(process.output)
                 ])
  end
  self
end

#status(process) ⇒ Symbol

Denote status from process

Returns:

  • (Symbol)


58
59
60
61
62
# File 'src/lib/grouik/helpers/process.rb', line 58

def status(process)
  statuses = { true => :success, false => :failure }

  statuses.fetch(process.success?)
end