Commit c8bc4a7d authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] new class Pod::Specification::Statistics

parent 84f9bd51
...@@ -5,11 +5,12 @@ module Pod ...@@ -5,11 +5,12 @@ module Pod
autoload :ErrorReport, 'cocoapods/command/error_report' autoload :ErrorReport, 'cocoapods/command/error_report'
autoload :Install, 'cocoapods/command/install' autoload :Install, 'cocoapods/command/install'
autoload :List, 'cocoapods/command/list' autoload :List, 'cocoapods/command/list'
autoload :Presenter, 'cocoapods/command/presenter'
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' autoload :Statistics, 'cocoapods/specification/statistics'
class Help < Informative class Help < Informative
def initialize(command_class, argv) def initialize(command_class, argv)
......
...@@ -37,8 +37,8 @@ module Pod ...@@ -37,8 +37,8 @@ module Pod
days = [1,2,3,5,8] days = [1,2,3,5,8]
dates, groups = {}, {} dates, groups = {}, {}
days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d} days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d}
Source.all_sets.sort_by {|set| set.creation_date}.each do |set| Source.all_sets.each do |set|
set_date = set.creation_date set_date = Pod::Specification::Statistics.new(set).creation_date
days.each do |d| days.each do |d|
if set_date > dates[d] if set_date > dates[d]
groups[d] = [] unless groups[d] groups[d] = [] unless groups[d]
...@@ -52,7 +52,7 @@ module Pod ...@@ -52,7 +52,7 @@ module Pod
sets = groups[d] sets = groups[d]
next unless sets next unless sets
puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}".yellow puts "Pods added in the last #{d == 1 ? '1 day' : "#{d} days"}".yellow
@presenter.present_sets(sets) @presenter.present_sets(sets.sort_by {|set| Pod::Specification::Statistics.new(set).creation_date})
end end
end end
......
...@@ -15,13 +15,13 @@ module Pod ...@@ -15,13 +15,13 @@ module Pod
end end
def present_set(set) def present_set(set)
stats = Pod::Specification::Statistics.new(set)
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts wrap_string(set.summary) puts wrap_string(stats.summary)
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification puts_detail('Homepage', stats.homepage)
puts_detail('Homepage', spec.homepage) puts_detail('Source', stats.source_url)
puts_detail('Source', spec.source_url) puts_detail('Watchers', stats.github_watchers) if @stats
puts_detail('Watchers', spec.github_watchers) if @stats puts_detail('Forks', stats.github_forks) if @stats
puts_detail('Forks', spec.github_forks) if @stats
puts puts
end end
......
...@@ -9,7 +9,8 @@ module Pod ...@@ -9,7 +9,8 @@ module Pod
end end
class Specification class Specification
autoload :Set, 'cocoapods/specification/set' autoload :Set, 'cocoapods/specification/set'
autoload :Statistics, 'cocoapods/specification/statistics'
# The file is expected to define and return a Pods::Specification. # The file is expected to define and return a Pods::Specification.
def self.from_file(path) def self.from_file(path)
...@@ -131,28 +132,6 @@ module Pod ...@@ -131,28 +132,6 @@ module Pod
@header_dir || pod_destroot_name @header_dir || pod_destroot_name
end end
def source_url
source.reject {|k,_| k == :commit || k == :tag }.values.first
end
def github_response
return @github_response if @github_response
github_url, username, reponame = *(source_url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
if github_url
@github_response = Net::HTTP.get('github.com', "/api/v2/json/repos/show/#{username}/#{reponame}")
end
end
def github_watchers
return "123"
github_response.match(/\"watchers\"\W*:\W*([0-9]+)/).to_a[1] if github_response
end
def github_forks
return "456"
github_response.match(/\"forks\"\W*:\W*([0-9]+)/).to_a[1] if github_response
end
attr_writer :compiler_flags attr_writer :compiler_flags
def compiler_flags def compiler_flags
flags = "#{@compiler_flags}" flags = "#{@compiler_flags}"
......
...@@ -67,40 +67,6 @@ module Pod ...@@ -67,40 +67,6 @@ module Pod
end.compact.sort.reverse end.compact.sort.reverse
end end
def creation_date
Dir.chdir(@pod_dir.dirname) do
@creation_date ||= Time.at(`git log --format=%ct ./#{name} | tail -1`.to_i)
end
end
def super_specification
@super_specification ||= specification.part_of_other_pod? ? specification.part_of_specification : specification
end
def homepage
super_specification.homepage
end
def description
super_specification.description
end
def summary
super_specification.summary
end
def source_url
super_specification.source_url
end
def github_watchers
super_specification.github_watchers
end
def github_forks
super_specification.github_forks
end
class External < Set class External < Set
def initialize(specification) def initialize(specification)
@specification = specification @specification = specification
......
require 'net/http'
module Pod
class Specification
class Statistics
def initialize(set)
@set = set
@spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
end
def creation_date
Dir.chdir(@set.pod_dir.dirname) do
@creation_date ||= Time.at(`git log --format=%ct ./#{@set.name} | tail -1`.to_i)
end
end
def homepage
@spec.homepage
end
def description
@spec.description
end
def summary
@spec.summary
end
def source_url
@spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
end
def github_response
return @github_response if @github_response
github_url, username, reponame = *(source_url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
if github_url
@github_response = Net::HTTP.get('github.com', "/api/v2/json/repos/show/#{username}/#{reponame}")
end
end
def github_watchers
github_response.match(/\"watchers\"\W*:\W*([0-9]+)/).to_a[1] if github_response
end
def github_forks
github_response.match(/\"forks\"\W*:\W*([0-9]+)/).to_a[1] if github_response
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