Class: Rapid::Check
- Inherits:
-
Object
- Object
- Rapid::Check
- Defined in:
- lib/rapid/check.rb
Class Attribute Summary collapse
-
.current ⇒ Object
Returns the value of attribute current.
-
.file ⇒ Object
Returns the value of attribute file.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#console ⇒ Object
Returns the value of attribute console.
-
#error_count ⇒ Object
readonly
Returns the value of attribute error_count.
-
#ok_count ⇒ Object
readonly
Returns the value of attribute ok_count.
-
#warning_count ⇒ Object
readonly
Returns the value of attribute warning_count.
Class Method Summary collapse
Instance Method Summary collapse
- #as_current ⇒ Object
- #check_count ⇒ Object
- #encounters_error? ⇒ Boolean
- #error(filename, message) ⇒ Object
- #exception(filename, e) ⇒ Object
-
#initialize(code, options = {}) ⇒ Check
constructor
A new instance of Check.
- #log_value(log_type, key, value) ⇒ Object
- #ok(filename, message) ⇒ Object
- #valid? ⇒ Boolean
- #warning(filename, message) ⇒ Object
- #with_section(name) ⇒ Object
Constructor Details
#initialize(code, options = {}) ⇒ Check
Returns a new instance of Check.
8 9 10 11 12 13 14 15 |
# File 'lib/rapid/check.rb', line 8 def initialize code, = {} @code = code @console = [:console] @ok_count = 0 @warning_count = 0 @error_count = 0 @sections = [] end |
Class Attribute Details
.current ⇒ Object
Returns the value of attribute current.
135 136 137 |
# File 'lib/rapid/check.rb', line 135 def current @current end |
.file ⇒ Object
Returns the value of attribute file.
135 136 137 |
# File 'lib/rapid/check.rb', line 135 def file @file end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/rapid/check.rb', line 5 def code @code end |
#console ⇒ Object
Returns the value of attribute console.
6 7 8 |
# File 'lib/rapid/check.rb', line 6 def console @console end |
#error_count ⇒ Object (readonly)
Returns the value of attribute error_count.
5 6 7 |
# File 'lib/rapid/check.rb', line 5 def error_count @error_count end |
#ok_count ⇒ Object (readonly)
Returns the value of attribute ok_count.
5 6 7 |
# File 'lib/rapid/check.rb', line 5 def ok_count @ok_count end |
#warning_count ⇒ Object (readonly)
Returns the value of attribute warning_count.
5 6 7 |
# File 'lib/rapid/check.rb', line 5 def warning_count @warning_count end |
Class Method Details
.new_with_detection(*args) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rapid/check.rb', line 145 def new_with_detection *args filename = file if filename.nil? possible_files.each do |name| if File.exists?(name) && !File.directory?(name) filename ||= name end end end unless filename raise FileNotFoundCheckError.new("could not locate your rapid.rb check file [#{Rapid::Check.possible_files.join(', ')}]. " + "Please create it or set the location using Rapid::Check.file = '/config/checks.rb'.") end code = File.open(filename) {|f| f.read } new code, *args end |
.possible_files ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/rapid/check.rb', line 137 def possible_files [ '.rapid', 'rapid.rb', File.join('config', 'rapid.rb') ] end |
Instance Method Details
#as_current ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/rapid/check.rb', line 87 def as_current self.class.current = self yield ensure self.class.current = nil end |
#check_count ⇒ Object
17 18 19 |
# File 'lib/rapid/check.rb', line 17 def check_count ok_count + warning_count + error_count end |
#encounters_error? ⇒ Boolean
95 96 97 98 99 |
# File 'lib/rapid/check.rb', line 95 def encounters_error? old_count = self.error_count yield old_count != self.error_count end |
#error(filename, message) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/rapid/check.rb', line 41 def error filename, @error_count += 1 @valid = false log :error, "", "" log :error, filename, log :error, "", "" end |
#exception(filename, e) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rapid/check.rb', line 49 def exception filename, e @error_count += 1 @valid = false log :error, "", "" log :error, filename, "" log :error, "", "" log :error, " problem: ", "content doesn't match" log :error, " after: ", pretty_code(e.previous_content, "START OF FILE") log :error, " expected:", pretty_code(e.expected_content, "END OF FILE") log :error, " received:", pretty_code(e.content, "END OF FILE") log :error, " current: ", clean_hash(e.result) log :error, "", "" end |
#log_value(log_type, key, value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rapid/check.rb', line 64 def log_value log_type, key, value return unless @console # don't print out very large strings if value.is_a?(String) && value.length > 50 value = value[0..23] + "..." + value[value.length - 23..-1] end log log_type, " #{key}:", value.inspect end |
#ok(filename, message) ⇒ Object
31 32 33 34 |
# File 'lib/rapid/check.rb', line 31 def ok filename, @ok_count += 1 log :ok, filename, end |
#valid? ⇒ Boolean
21 22 23 24 25 26 27 28 29 |
# File 'lib/rapid/check.rb', line 21 def valid? @valid = true @ok_count = 0 @warning_count = 0 @error_count = 0 as_current { eval code } @valid end |
#warning(filename, message) ⇒ Object
36 37 38 39 |
# File 'lib/rapid/check.rb', line 36 def warning filename, @warning_count += 1 log :warning, filename, end |
#with_section(name) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rapid/check.rb', line 75 def with_section name puts "" if @sections.empty? && @console indention = " " * @sections.length puts "#{indention}#{name}" if @console @sections.push name yield ensure @sections.pop end |