Class: Enforce::Handler

Inherits:
DSL
  • Object
show all
Includes:
Colors
Defined in:
lib/enforce/handler.rb

Instance Attribute Summary

Attributes inherited from DSL

#last_file

Instance Method Summary collapse

Methods included from Colors

#colors, #say

Methods inherited from DSL

#failed_results, #file, #folder, #no_file, #passed_results, #results, #with, #with_line, #without, #without_line

Instance Method Details

#execute(file) ⇒ Object



7
8
9
10
11
# File 'lib/enforce/handler.rb', line 7

def execute(file)
  eval File.read file
  color = failed? ? "%{red}" : "%{green}"
  say "#{color}#{results.count} rules, #{failed} failures"
end

#failedObject



13
14
15
# File 'lib/enforce/handler.rb', line 13

def failed
  failed_results.count
end

#failed?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/enforce/handler.rb', line 17

def failed?
  failed_results.count > 0
end

#handle(message:, pass:) ⇒ Object



21
22
23
24
# File 'lib/enforce/handler.rb', line 21

def handle(message:, pass:)
  status = pass ? "%{green}PASS%{reset}" : "%{red}FAIL%{reset}"
  say "#{status}  #{message}"
end