Class: Fdlint::Validator
- Includes:
- Helper::Logger
- Defined in:
- lib/fdlint/validator.rb
Constant Summary
Constants included from Helper::Logger
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#syntax ⇒ Object
readonly
Returns the value of attribute syntax.
Instance Method Summary collapse
-
#initialize(path = nil, options = {}) ⇒ Validator
constructor
A new instance of Validator.
- #validate ⇒ Object
- #validate_content ⇒ Object
- #validate_file ⇒ Object
Methods included from Helper::Logger
Constructor Details
#initialize(path = nil, options = {}) ⇒ Validator
Returns a new instance of Validator.
17 18 19 20 21 22 |
# File 'lib/fdlint/validator.rb', line 17 def initialize( path = nil, = {} ) @file = path @source = [:text] @syntax = [:syntax] || Helper::CodeType.guess( source, file ) @log_level = [:log_level] end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
13 14 15 |
# File 'lib/fdlint/validator.rb', line 13 def file @file end |
#log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
13 14 15 |
# File 'lib/fdlint/validator.rb', line 13 def log_level @log_level end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
13 14 15 |
# File 'lib/fdlint/validator.rb', line 13 def results @results end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
13 14 15 |
# File 'lib/fdlint/validator.rb', line 13 def source @source end |
#syntax ⇒ Object (readonly)
Returns the value of attribute syntax.
13 14 15 |
# File 'lib/fdlint/validator.rb', line 13 def syntax @syntax end |
Instance Method Details
#validate ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fdlint/validator.rb', line 24 def validate @results = [] begin @source ||= read_file validate_file if file validate_content rescue EncodingError results << InvalidFileEncoding.new end filter_results_by_log_level if log_level if block_given? yield file, source, results else results end end |
#validate_content ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/fdlint/validator.rb', line 54 def validate_content if source.valid_encoding? self << parse.flatten else self << [InvalidFileEncoding.new] end end |