Commit 4c3544dc authored by Fabio Pelosin's avatar Fabio Pelosin

Don't initialize Spec::Set::Statistics if not needed

See #919
parent 8be4e89a
......@@ -33,7 +33,9 @@ module Pod
#
MAX_CACHE_SIZE = 500
Pod::Specification::Set::Statistics.instance.cache_file = CACHE_ROOT + 'statistics.yml'
# @return [Pathname] The file to use a cache of the statistics provider.
#
STATISTICS_CACHE_FILE = CACHE_ROOT + 'statistics.yml'
autoload :Command, 'cocoapods/command'
autoload :Executable, 'cocoapods/executable'
......
......@@ -8,6 +8,16 @@ module Pod
class Command < CLAide::Command
require 'cocoapods/command/list'
require 'cocoapods/command/outdated'
require 'cocoapods/command/project'
require 'cocoapods/command/push'
require 'cocoapods/command/repo'
require 'cocoapods/command/search'
require 'cocoapods/command/setup'
require 'cocoapods/command/spec'
require 'cocoapods/command/inter_process_communication'
self.abstract_command = true
self.command = 'pod'
self.description = 'CocoaPods, the Objective-C library package manager.'
......@@ -102,12 +112,3 @@ module Pod
end
end
require 'cocoapods/command/list'
require 'cocoapods/command/outdated'
require 'cocoapods/command/project'
require 'cocoapods/command/push'
require 'cocoapods/command/repo'
require 'cocoapods/command/search'
require 'cocoapods/command/setup'
require 'cocoapods/command/spec'
require 'cocoapods/command/inter_process_communication'
......@@ -48,7 +48,8 @@ module Pod
dates, groups = {}, {}
days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d}
sets = SourcesManager.all_sets
creation_dates = Specification::Set::Statistics.instance.creation_dates(sets)
statistics_provider = Specification::Set::Statistics.new(STATISTICS_CACHE_FILE)
creation_dates = statistics_provider.creation_dates(sets)
sets.each do |set|
set_date = creation_dates[set.name]
......@@ -65,7 +66,8 @@ module Pod
next unless sets
UI.section("\nPods added in the last #{"day".pluralize(d)}".yellow) do
sorted = sets.sort_by {|s| creation_dates[s.name]}
sorted.each { |set| UI.pod(set, (@stats ? :stats : :name)) }
mode = @stats ? :stats : :name
sorted.each { |set| UI.pod(set, mode, statistics_provider) }
end
end
end
......
......@@ -42,9 +42,15 @@ module Pod
if @supported_on_osx
sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
end
statistics_provider = Specification::Set::Statistics.new(STATISTICS_CACHE_FILE)
sets.each do |set|
begin
UI.pod(set, (@stats ? :stats : :normal))
if @stats
UI.pod(set, :stats, statistics_provider)
else
UI.pod(set, :normal)
end
rescue DSLError
UI.warn "Skipping `#{set.name}` because the podspec contains errors."
end
......
......@@ -157,11 +157,11 @@ module Pod
# Prints the textual representation of a given set.
#
def pod(set, mode = :normal)
def pod(set, mode = :normal, statistics_provider = nil)
if mode == :name
puts_indented set.name
else
pod = Specification::Set::Presenter.new(set)
pod = Specification::Set::Presenter.new(set, statistics_provider)
title("\n-> #{pod.name} (#{pod.version})".green, '', 1) do
puts_indented pod.summary
labeled('Homepage', pod.homepage)
......
......@@ -7,7 +7,6 @@ module Pod
before do
@set = SourcesManager.search(Dependency.new('CocoaLumberjack'))
Specification::Set::Statistics.instance.cache_file = nil
end
it "presents the name, version, description, homepage and source of a specification set" do
......
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