Class: RubyLint::Report
- Inherits:
-
Object
- Object
- RubyLint::Report
- Defined in:
- lib/ruby-lint/report.rb,
lib/ruby-lint/report/entry.rb
Overview
Report is a data container for error messages, warnings, informational messages and other custom defined types of messages. It should be used by the various analysis classes to store information such as errors for undefined variables and warnings for potentially confusing code.
Levels
Each instance can add entries for a set of predefined reporting levels. By default the following levels are defined:
- error
- warning
- info
Unless other levels are specified when creating an instance these levels are used for each new instance. Extra levels can be specified in the constructor of this class.
Adding Entries
Adding entries can be done by either calling #add:
report = RubyLint::Report.new
report.add(
:level => :info,
:message => 'informational message',
:line => 1,
:column => 2,
:file => 'file.rb'
)
When using #add any invalid/disabled reporting levels will be silently ignored. This makes it easier for code to add entries of a particular level without having to manually check if said level is enabled.
Defined Under Namespace
Classes: Entry
Constant Summary
- DEFAULT_LEVELS =
Reporting levels that are always available.
[:error, :warning, :info].freeze
Instance Attribute Summary collapse
-
#entries ⇒ Array
readonly
The entries of the report.
-
#levels ⇒ Array
readonly
The enabled levels of the report.
Instance Method Summary collapse
-
#add(attributes) ⇒ Object
Adds a new entry to the report.
-
#initialize(levels = DEFAULT_LEVELS) ⇒ Report
constructor
A new instance of Report.
-
#valid_level?(level) ⇒ TrueClass|FalseClass
private
Constructor Details
#initialize(levels = DEFAULT_LEVELS) ⇒ Report
Returns a new instance of Report
58 59 60 61 |
# File 'lib/ruby-lint/report.rb', line 58 def initialize(levels = DEFAULT_LEVELS) @levels = levels.map(&:to_sym) @entries = [] end |
Instance Attribute Details
#entries ⇒ Array (readonly)
Returns The entries of the report.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby-lint/report.rb', line 45 class Report attr_reader :entries, :levels ## # Reporting levels that are always available. # # @return [Array] # DEFAULT_LEVELS = [:error, :warning, :info].freeze ## # @param [Array] levels The reporting levels to enable for this instance. # def initialize(levels = DEFAULT_LEVELS) @levels = levels.map(&:to_sym) @entries = [] end ## # Adds a new entry to the report. # # @param [Hash] attributes # @option attributes [Symbol] :level The level of the message. # # @see RubyLint::Report::Entry#initialize # def add(attributes) level = attributes[:level].to_sym if valid_level?(level) entries << Entry.new(attributes) end end private ## # @param [Symbol] level # @return [TrueClass|FalseClass] # def valid_level?(level) return levels.include?(level) end end |
#levels ⇒ Array (readonly)
Returns The enabled levels of the report.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruby-lint/report.rb', line 45 class Report attr_reader :entries, :levels ## # Reporting levels that are always available. # # @return [Array] # DEFAULT_LEVELS = [:error, :warning, :info].freeze ## # @param [Array] levels The reporting levels to enable for this instance. # def initialize(levels = DEFAULT_LEVELS) @levels = levels.map(&:to_sym) @entries = [] end ## # Adds a new entry to the report. # # @param [Hash] attributes # @option attributes [Symbol] :level The level of the message. # # @see RubyLint::Report::Entry#initialize # def add(attributes) level = attributes[:level].to_sym if valid_level?(level) entries << Entry.new(attributes) end end private ## # @param [Symbol] level # @return [TrueClass|FalseClass] # def valid_level?(level) return levels.include?(level) end end |
Instance Method Details
#add(attributes) ⇒ Object
Adds a new entry to the report.
71 72 73 74 75 76 77 |
# File 'lib/ruby-lint/report.rb', line 71 def add(attributes) level = attributes[:level].to_sym if valid_level?(level) entries << Entry.new(attributes) end end |
#valid_level?(level) ⇒ TrueClass|FalseClass (private)
85 86 87 |
# File 'lib/ruby-lint/report.rb', line 85 def valid_level?(level) return levels.include?(level) end |