Commit 6ae76658 authored by Fabio Pelosin's avatar Fabio Pelosin

[refactor] moved spec_present module to presenter class

parent 31b6da64
...@@ -3,13 +3,13 @@ require 'colored' ...@@ -3,13 +3,13 @@ require 'colored'
module Pod module Pod
class Command class Command
autoload :ErrorReport, 'cocoapods/command/error_report' autoload :ErrorReport, 'cocoapods/command/error_report'
autoload :SetPresent, 'cocoapods/command/set_present'
autoload :Install, 'cocoapods/command/install' autoload :Install, 'cocoapods/command/install'
autoload :List, 'cocoapods/command/list' autoload :List, 'cocoapods/command/list'
autoload :Repo, 'cocoapods/command/repo' autoload :Repo, 'cocoapods/command/repo'
autoload :Search, 'cocoapods/command/search' autoload :Search, 'cocoapods/command/search'
autoload :Setup, 'cocoapods/command/setup' autoload :Setup, 'cocoapods/command/setup'
autoload :Spec, 'cocoapods/command/spec' autoload :Spec, 'cocoapods/command/spec'
autoload :Presenter, 'cocoapods/command/presenter'
class Help < Informative class Help < Informative
def initialize(command_class, argv) def initialize(command_class, argv)
......
...@@ -15,22 +15,20 @@ module Pod ...@@ -15,22 +15,20 @@ module Pod
end end
def self.options def self.options
SetPresent.set_present_options + SetPresent.options + super
super
end end
include SetPresent
extend Executable extend Executable
executable :git executable :git
def initialize(argv) def initialize(argv)
parse_set_options(argv)
@new = argv.option('new') @new = argv.option('new')
@presenter = Presenter.new(argv)
super unless argv.empty? super unless argv.empty?
end end
def list_all def list_all
present_sets(all = Source.all_sets) @presenter.present_sets(all = Source.all_sets)
puts "#{all.count} pods were found" puts "#{all.count} pods were found"
puts puts
end end
...@@ -53,15 +51,15 @@ module Pod ...@@ -53,15 +51,15 @@ module Pod
days.reverse.each do |d| days.reverse.each do |d|
sets = groups[d] sets = groups[d]
next unless sets next unless sets
puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}\n".yellow puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}".yellow
present_sets(sets) @presenter.present_sets(sets)
end end
end end
def run def run
if @new if @new
puts "\nUpdating Spec Repositories\n".yellow if config.verbose? puts "\nUpdating Spec Repositories\n".yellow if config.verbose?
Repo.new(ARGV.new(["update"])).run #Repo.new(ARGV.new(["update"])).run
list_new list_new
else else
list_all list_all
......
...@@ -2,41 +2,32 @@ require 'net/http' ...@@ -2,41 +2,32 @@ require 'net/http'
module Pod module Pod
class Command class Command
module SetPresent class Presenter
def self.set_present_options def self.options
" --name-only Show only the names of the pods\n" +
" --stats Show additional stats (like GitHub watchers and forks)\n" " --stats Show additional stats (like GitHub watchers and forks)\n"
end end
def list def initialize(argv)
@list
end
def parse_set_options(argv)
@stats = argv.option('--stats') @stats = argv.option('--stats')
@list = argv.option('--name-only')
end end
def present_sets(array) def present_sets(array)
puts
array.each {|set| present_set(set)} array.each {|set| present_set(set)}
end end
def present_set(set) def present_set(set)
if @list puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts set.name puts_wrapped_text(set.summary)
else spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts_wrapped_text(set.summary) puts_detail('Homepage', spec.homepage)
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification puts_detail('Source', spec.source_url)
if @stats
puts_detail('Homepage', spec.homepage) puts_detail('Watchers', spec.github_watchers)
puts_detail('Source', spec.source_url) puts_detail('Forks', spec.github_forks)
if @stats
puts_detail('Watchers', spec.github_watchers)
puts_detail('Forks', spec.github_forks)
end
puts
end end
puts
end end
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/ # adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
......
...@@ -13,23 +13,19 @@ module Pod ...@@ -13,23 +13,19 @@ module Pod
def self.options def self.options
" --full Search by name, summary, and description\n" + " --full Search by name, summary, and description\n" +
SetPresent.set_present_options + Presenter.options + super
super
end end
include SetPresent
def initialize(argv) def initialize(argv)
parse_set_options(argv)
@full_text_search = argv.option('--full') @full_text_search = argv.option('--full')
unless @query = argv.arguments.first @presenter = Presenter.new(argv)
super @query = argv.shift_argument
end super unless argv.empty? && @query
end end
def run def run
sets = Source.search_by_name(@query.strip, @full_text_search) sets = Source.search_by_name(@query.strip, @full_text_search)
present_sets(sets) @presenter.present_sets(sets)
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment