Commit 85827809 authored by Fabio Pelosin's avatar Fabio Pelosin

[pod-list] refactoring

parent e46364e6
...@@ -29,12 +29,8 @@ module Pod ...@@ -29,12 +29,8 @@ module Pod
super unless argv.empty? super unless argv.empty?
end end
def dir
config.repos_dir + 'master'
end
def last_check_file def last_check_file
config.repos_dir + 'list_new.txt' config.repos_dir + 'list_new'
end end
def update_last_check_time(time) def update_last_check_time(time)
...@@ -48,7 +44,7 @@ module Pod ...@@ -48,7 +44,7 @@ module Pod
Time.now - 60 * 60 * 24 * 15 Time.now - 60 * 60 * 24 * 15
end end
def new_specs_since(time) def new_sets_since(time)
all = Source.all_sets all = Source.all_sets
all.reject! {|set| (set.creation_date - time).to_i <= 0 } all.reject! {|set| (set.creation_date - time).to_i <= 0 }
all.sort_by {|set| set.creation_date} all.sort_by {|set| set.creation_date}
...@@ -57,7 +53,7 @@ module Pod ...@@ -57,7 +53,7 @@ module Pod
def list_new def list_new
time = last_check_time time = last_check_time
time_string = time.strftime("%A %m %B %Y (%H:%M)") time_string = time.strftime("%A %m %B %Y (%H:%M)")
sets = new_specs_since(time) sets = new_sets_since(time)
if sets.empty? if sets.empty?
puts "\nNo new pods were added since #{time.localtime}" unless list puts "\nNo new pods were added since #{time.localtime}" unless list
else else
...@@ -77,7 +73,7 @@ module Pod ...@@ -77,7 +73,7 @@ module Pod
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
......
...@@ -8,7 +8,7 @@ module Pod ...@@ -8,7 +8,7 @@ module Pod
" --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 list
@list @list
end end
...@@ -18,9 +18,7 @@ module Pod ...@@ -18,9 +18,7 @@ module Pod
end end
def present_sets(array) def present_sets(array)
array.each do |set| array.each {|set| present_set(set)}
present_set(set)
end
end end
def present_set(set) def present_set(set)
...@@ -28,15 +26,14 @@ module Pod ...@@ -28,15 +26,14 @@ module Pod
puts set.name puts set.name
else else
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green 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 spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
puts_detail('Homepage', spec.homepage) puts_detail('Homepage', spec.homepage)
puts_detail('Source', spec.source_url) puts_detail('Source', spec.source_url)
if @stats if @stats
stats = stats(spec.source_url) puts_detail('Watchers', spec.github_watchers)
puts_detail('Watchers', stats[:watchers]) puts_detail('Forks', spec.github_forks)
puts_detail('Forks', stats[:forks])
end end
puts puts
end end
...@@ -55,18 +52,6 @@ module Pod ...@@ -55,18 +52,6 @@ module Pod
spaces = ' ' * number_of_spaces spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}" puts " - #{title}: #{spaces + string}"
end 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 end
end end
...@@ -135,6 +135,24 @@ module Pod ...@@ -135,6 +135,24 @@ module Pod
source.reject {|k,_| k == :commit || k == :tag }.values.first source.reject {|k,_| k == :commit || k == :tag }.values.first
end 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}"
......
...@@ -73,6 +73,34 @@ module Pod ...@@ -73,6 +73,34 @@ module Pod
end end
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
......
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