Class: Syntaxer::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/syntaxer/printer.rb

Overview

Print system messages

Constant Summary collapse

NON_EXISTENT_RULE_MESSAGE =
"exec_rule `%s` for language %s not exists. Skip"
@@bar =
nil
@@not_exists_rules =
[]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.count_of_filesObject

Returns the value of attribute count_of_files.



11
12
13
# File 'lib/syntaxer/printer.rb', line 11

def count_of_files
  @count_of_files
end

.loudObject

Returns the value of attribute loud.



11
12
13
# File 'lib/syntaxer/printer.rb', line 11

def loud
  @loud
end

.modeObject

Returns the value of attribute mode.



11
12
13
# File 'lib/syntaxer/printer.rb', line 11

def mode
  @mode
end

.quiteObject

Returns the value of attribute quite.



11
12
13
# File 'lib/syntaxer/printer.rb', line 11

def quite
  @quite
end

Class Method Details



60
61
62
63
64
65
66
67
68
69
# File 'lib/syntaxer/printer.rb', line 60

def print_message filestatus
  return if @quite
  puts "\n"
  print filestatus.file_name
  puts " OK".color(:green) if filestatus.status == :ok && @loud
  puts "\nErrors:".color(:red) if filestatus.status == :failed
  filestatus.errors.each do |error|
    puts "\t #{error}".color(:red)
  end
end

Print error message for each if file

Parameters:

  • files (Array, #each)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/syntaxer/printer.rb', line 40

def print_result checker
  return if @quite
  puts "\n"
  puts "Syntax OK".color(:green) if checker.error_files.empty? && $stdmyout.string.empty?

  @loud ? (files = checker.all_files) : (files = checker.error_files)
  files.each do |file|
    print_message(file)
  end
  
  unless @@not_exists_rules.empty?
    puts "\n"
    @@not_exists_rules.each do |rule|
      puts (NON_EXISTENT_RULE_MESSAGE % [rule.executor, rule.name]).color(:yellow)
    end
  end
  
  $stderr.puts("\nErrors:"+"\n\t"+$stdmyout.string.color(:red)) unless $stdmyout.string.empty?
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
18
19
20
# File 'lib/syntaxer/printer.rb', line 13

def setup &block
  yield self if block_given?
  if @mode == :hook
    @@bar = Syntaxer::ProgressBar.new
  else
    @@bar = ::ProgressBar.new(@count_of_files, :bar, :counter)
  end
end

.update(*args) ⇒ Object

Show progress

Parameters:

  • (true|false) (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/syntaxer/printer.rb', line 26

def update *args #not_exists_rule = nil, file_status = (status=true;)
  args = args.first
  @@not_exists_rules << args[:rule] if args.include?(:rule) && !@@not_exists_rules.include?(args[:rule])
  return if @quite
  if args.include?(:file_status)
    @mode == :hook ? @@bar.increment!(args[:file_status]) : @@bar.increment!
  end
  true
end