Skip to content

Commit

Permalink
Move the Linter::Result class into its own file.
Browse files Browse the repository at this point in the history
Clears up a bit of the clutter inside of linter.rb and makes it clearly
it's own entity within the linter.
  • Loading branch information
joshkalpin committed Dec 6, 2013
1 parent 88f665e commit 6b3de00
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 71 deletions.
45 changes: 2 additions & 43 deletions lib/cocoapods-core/specification/linter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'cocoapods-core/specification/linter/result'

module Pod
class Specification

Expand Down Expand Up @@ -500,49 +502,6 @@ def add_result(type, message)
end
result.platforms << consumer.platform_name if consumer
end

#-----------------------------------------------------------------------#

class Result

# @return [Symbol] the type of result.
#
attr_reader :type

# @return [String] the message associated with result.
#
attr_reader :message

# @param [Symbol] type @see type
# @param [String] message @see message
#
def initialize(type, message)
@type = type
@message = message
@platforms = []
end

# @return [Array<Platform>] the platforms where this result was
# generated.
#
attr_reader :platforms

# @return [String] a string representation suitable for UI output.
#
def to_s
r = "[#{type.to_s.upcase}] #{message}"
if platforms != Specification::PLATFORMS
platforms_names = platforms.uniq.map do |p|
Platform.string_name(p)
end
r << " [#{platforms_names * ' - '}]" unless platforms.empty?
end
r
end
end

#-----------------------------------------------------------------------#

end
end
end
Expand Down
43 changes: 43 additions & 0 deletions lib/cocoapods-core/specification/linter/result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Pod
class Specification
class Linter
class Result

# @return [Symbol] the type of result.
#
attr_reader :type

# @return [String] the message associated with result.
#
attr_reader :message

# @param [Symbol] type @see type
# @param [String] message @see message
#
def initialize(type, message)
@type = type
@message = message
@platforms = []
end

# @return [Array<Platform>] the platforms where this result was
# generated.
#
attr_reader :platforms

# @return [String] a string representation suitable for UI output.
#
def to_s
r = "[#{type.to_s.upcase}] #{message}"
if platforms != Specification::PLATFORMS
platforms_names = platforms.uniq.map do |p|
Platform.string_name(p)
end
r << " [#{platforms_names * ' - '}]" unless platforms.empty?
end
r
end
end
end
end
end
27 changes: 27 additions & 0 deletions spec/specification/linter/result_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Specification::Linter::Result do
before do
@result = Specification::Linter::Result.new(:error, 'This is a sample error.')
end

it "returns the type" do
@result.type.should == :error
end

it "returns the message" do
@result.message.should == 'This is a sample error.'
end

it "can store the platforms that generated the result" do
@result.platforms << :ios
@result.platforms.should == [:ios]
end

it "returns a string representation suitable for UI" do
@result.to_s.should == '[ERROR] This is a sample error.'
@result.platforms << :ios
@result.to_s.should == '[ERROR] This is a sample error. [iOS]'
end
end
end
28 changes: 0 additions & 28 deletions spec/specification/linter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,33 +394,5 @@ def message_should_include(*values)
message.should.match /post install hook.*deprecated/
end
end

end

#---------------------------------------------------------------------------#

describe Specification::Linter::Result do
before do
@result = Specification::Linter::Result.new(:error, 'This is a sample error.')
end

it "returns the type" do
@result.type.should == :error
end

it "returns the message" do
@result.message.should == 'This is a sample error.'
end

it "can store the platforms that generated the result" do
@result.platforms << :ios
@result.platforms.should == [:ios]
end

it "returns a string representation suitable for UI" do
@result.to_s.should == '[ERROR] This is a sample error.'
@result.platforms << :ios
@result.to_s.should == '[ERROR] This is a sample error. [iOS]'
end
end
end

1 comment on commit 6b3de00

@fabiopelosin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.