Commit 85827809 authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] refactoring

parent e46364e6
......@@ -29,12 +29,8 @@ module Pod
super unless argv.empty?
end
def dir
config.repos_dir + 'master'
end
def last_check_file
config.repos_dir + 'list_new.txt'
config.repos_dir + 'list_new'
end
def update_last_check_time(time)
......@@ -48,7 +44,7 @@ module Pod
Time.now - 60 * 60 * 24 * 15
end
def new_specs_since(time)
def new_sets_since(time)
all = Source.all_sets
all.reject! {|set| (set.creation_date - time).to_i <= 0 }
all.sort_by {|set| set.creation_date}
......@@ -57,7 +53,7 @@ module Pod
def list_new
time = last_check_time
time_string = time.strftime("%A %m %B %Y (%H:%M)")
sets = new_specs_since(time)
sets = new_sets_since(time)
if sets.empty?
puts "\nNo new pods were added since #{time.localtime}" unless list
else
......@@ -77,7 +73,7 @@ module Pod
def run
if @new
puts "\nUpdating Spec Repositories\n".yellow if config.verbose?
#Repo.new(ARGV.new(["update"])).run
Repo.new(ARGV.new(["update"])).run
list_new
else
list_all
......
......@@ -8,7 +8,7 @@ module Pod
" --stats Show additional stats (like GitHub watchers and forks)\n"
end
def list
def list
@list
end
......@@ -18,9 +18,7 @@ module Pod
end
def present_sets(array)
array.each do |set|
present_set(set)
end
array.each {|set| present_set(set)}
end
def present_set(set)
......@@ -28,15 +26,14 @@ module Pod
puts set.name
else
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts_wrapped_text(set.specification.summary)
puts_wrapped_text(set.summary)
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
puts_detail('Homepage', spec.homepage)
puts_detail('Source', spec.source_url)
if @stats
stats = stats(spec.source_url)
puts_detail('Watchers', stats[:watchers])
puts_detail('Forks', stats[:forks])
puts_detail('Watchers', spec.github_watchers)
puts_detail('Forks', spec.github_forks)
end
puts
end
......@@ -55,18 +52,6 @@ module Pod
spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}"
end
def stats(url)
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
result = {}
if original_url
gh_response = Net::HTTP.get('github.com', "/api/v2/json/repos/show/#{username}/#{reponame}")
result[:watchers] = gh_response.match(/\"watchers\"\W*:\W*([0-9]+)/).to_a[1]
result[:forks] = gh_response.match(/\"forks\"\W*:\W*([0-9]+)/).to_a[1]
end
result
end
end
end
end
......@@ -135,6 +135,24 @@ module Pod
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
def compiler_flags
flags = "#{@compiler_flags}"
......
......@@ -73,6 +73,34 @@ module Pod
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
def initialize(specification)
@specification = specification
......
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