Skip to content

Commit

Permalink
Document Analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Feb 14, 2012
1 parent 31d09af commit 8ae7f0a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pelusa.rb
Expand Up @@ -3,7 +3,7 @@ module Pelusa
#
# Returns an Array of results of a given Reporter
def self.run(files=[], reporter=RubyReporter, lints=Lint.all)
if Array(files).empty?
if files.empty?
files = Dir["**/*.rb"]
end

Expand Down
39 changes: 39 additions & 0 deletions lib/pelusa/analysis.rb
@@ -1,4 +1,20 @@
module Pelusa
# Public: An Analysis the result of applying a Lint check to a class.
#
# Examples
#
# analysis = SuccessfulAnalysis.new("Is below 50 lines")
# analysis.successful?
# # => true
#
# failure = FailedAnalysis.new("Is below 50 lines", 123) do |lines|
# "There are too many lines (#{lines})"
# end
# failure.successful?
# # => false
# failure.message
# # => "There are too many lines (123)"
#
class Analysis
def initialize(name)
@name = name
Expand All @@ -25,23 +41,46 @@ def status
end
end

# Public: A SuccessfulAnalysis is an analysis that has passed a particular
# lint check.
#
class SuccessfulAnalysis < Analysis
# Public: A successful analysis is always successful, obviously.
#
# Returns true.
def successful?
true
end
end

# Public: A FailedAnalysis is an analysis that has failed a particular
# lint check.
#
class FailedAnalysis < Analysis
# Public: Initializes a new FailedAnalysis.
#
# name - The name of the lint check.
# payload - An object to use in the message to aid the user in fixing the
# problem.
# block - A block to generate the message. It must yield the payload
# object.
def initialize(name, payload, &block)
super(name)
@payload = payload
@block = block
end

# Public: A failed analysis is never successful , obviously.
#
# Returns false.
def successful?
false
end

# Public: Generates an explicative message yielding the payload object to
# the block, so that the user gets some hint to fix the problem.
#
# Returns the String message.
def message
@block.call(@payload)
end
Expand Down

0 comments on commit 8ae7f0a

Please sign in to comment.