Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
cf3bcecb
Commit
cf3bcecb
authored
Apr 11, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[pod-list] caching for statistics & refactoring
parent
29a517d1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
35 deletions
+103
-35
list.rb
lib/cocoapods/command/list.rb
+7
-4
presenter.rb
lib/cocoapods/command/presenter.rb
+41
-6
source.rb
lib/cocoapods/source.rb
+1
-1
statistics.rb
lib/cocoapods/specification/statistics.rb
+54
-24
No files found.
lib/cocoapods/command/list.rb
View file @
cf3bcecb
...
...
@@ -37,10 +37,13 @@ module Pod
days
=
[
1
,
2
,
3
,
5
,
8
]
dates
,
groups
=
{},
{}
days
.
each
{
|
d
|
dates
[
d
]
=
Time
.
now
-
60
*
60
*
24
*
d
}
Source
.
all_sets
.
each
do
|
set
|
set_date
=
Pod
::
Specification
::
Statistics
.
new
(
set
).
creation_date
sets
=
Source
.
all_sets
creation_dates
=
Pod
::
Specification
::
Statistics
.
instance
.
creation_dates
(
sets
)
sets
.
each
do
|
set
|
set_date
=
creation_dates
[
set
.
name
]
days
.
each
do
|
d
|
if
set_date
>
dates
[
d
]
if
set_date
>
=
dates
[
d
]
groups
[
d
]
=
[]
unless
groups
[
d
]
groups
[
d
]
<<
set
break
...
...
@@ -52,7 +55,7 @@ module Pod
sets
=
groups
[
d
]
next
unless
sets
puts
"Pods added in the last
#{
d
==
1
?
'1 day'
:
"
#{
d
}
days"
}
"
.
yellow
@presenter
.
present_sets
(
sets
.
sort_by
{
|
set
|
Pod
::
Specification
::
Statistics
.
new
(
set
).
creation_date
})
@presenter
.
present_sets
(
sets
.
sort_by
{
|
set
|
creation_dates
[
set
.
name
]
})
end
end
...
...
lib/cocoapods/command/presenter.rb
View file @
cf3bcecb
module
Pod
class
Specification
class
Set
def
main_specification
specification
.
part_of_other_pod?
?
specification
.
part_of_specification
:
specification
end
def
homepage
main_specification
.
homepage
end
def
description
main_specification
.
description
end
def
summary
main_specification
.
summary
end
def
source_url
main_specification
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
end
def
github_watchers
Pod
::
Specification
::
Statistics
.
instance
.
github_watchers
(
self
)
end
def
github_forks
Pod
::
Specification
::
Statistics
.
instance
.
github_watchers
(
self
)
end
end
end
end
module
Pod
class
Command
class
Presenter
...
...
@@ -15,16 +49,17 @@ module Pod
end
def
present_set
(
set
)
stats
=
Pod
::
Specification
::
Statistics
.
new
(
set
)
puts
"-->
#{
set
.
name
}
(
#{
set
.
versions
.
reverse
.
join
(
", "
)
}
)"
.
green
puts
wrap_string
(
s
tats
.
summary
)
puts_detail
(
'Homepage'
,
s
tats
.
homepage
)
puts_detail
(
'Source'
,
s
tats
.
source_url
)
puts_detail
(
'Watchers'
,
s
tats
.
github_watchers
)
if
@stats
puts_detail
(
'Forks'
,
s
tats
.
github_forks
)
if
@stats
puts
wrap_string
(
s
et
.
summary
)
puts_detail
(
'Homepage'
,
s
et
.
homepage
)
puts_detail
(
'Source'
,
s
et
.
source_url
)
puts_detail
(
'Watchers'
,
s
et
.
github_watchers
)
if
@stats
puts_detail
(
'Forks'
,
s
et
.
github_forks
)
if
@stats
puts
end
private
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
def
wrap_string
(
txt
,
col
=
80
,
indentation
=
4
)
indent
=
' '
*
indentation
...
...
lib/cocoapods/source.rb
View file @
cf3bcecb
...
...
@@ -13,7 +13,7 @@ module Pod
end
def
all_sets
all
.
map
!
{
|
source
|
source
.
pod_sets
}.
flatten
all
.
map
{
|
source
|
source
.
pod_sets
}.
flatten
end
def
search
(
dependency
)
...
...
lib/cocoapods/specification/statistics.rb
View file @
cf3bcecb
require
'net/http'
require
'yaml'
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
include
Config
::
Mixin
def
creation_date
Dir
.
chdir
(
@set
.
pod_dir
.
dirname
)
do
@creation_date
||=
Time
.
at
(
`git log --format=%ct ./
#{
@set
.
name
}
| tail -1`
.
to_i
)
def
self
.
instance
@instance
||=
new
end
def
self
.
instance
=
(
instance
)
@instance
=
instance
end
def
homepag
e
@
spec
.
homepage
def
initializ
e
@
cache
=
cache_file
.
exist?
?
YAML
::
load
(
cache_file
.
read
)
:
{}
end
def
description
@spec
.
description
def
creation_dates
(
sets
)
creation_dates
=
{}
sets
.
each
do
|
set
|
@cache
[
set
.
name
]
||=
{}
date
=
@cache
[
set
.
name
][
:creation_date
]
||=
compute_creation_date
(
set
)
creation_dates
[
set
.
name
]
=
date
end
save_cache_file
creation_dates
end
def
summary
@spec
.
summary
def
github_watchers
(
set
)
compute_github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_watchers
]
if
@cache
[
set
.
name
]
end
def
source_url
@spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
def
github_forks
(
set
)
compute_github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_forks
]
if
@cache
[
set
.
name
]
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
}
"
)
private
def
cache_file
Config
.
instance
.
repos_dir
+
'statistics.yml'
end
def
save_cache_file
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
@cache
))
}
end
def
github_watchers
github_response
.
match
(
/\"watchers\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
github_response
def
compute_creation_date
(
set
)
Dir
.
chdir
(
set
.
pod_dir
.
dirname
)
do
Time
.
at
(
`git log --first-parent --format=%ct
#{
set
.
name
}
`
.
split
(
"
\n
"
).
last
.
to_i
)
end
end
def
github_forks
github_response
.
match
(
/\"forks\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
github_response
def
compute_github_stats_if_needed
(
set
)
if
@cache
[
set
.
name
]
&&
@cache
[
set
.
name
][
:github_check_date
]
&&
@cache
[
set
.
name
][
:github_check_date
]
>
Time
.
now
-
60
*
60
return
end
spec
=
set
.
specification
.
part_of_other_pod?
?
set
.
specification
.
part_of_specification
:
set
.
specification
source_url
=
spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
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
}
"
)
watchers
=
github_response
.
match
(
/\"watchers\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
forks
=
github_response
.
match
(
/\"forks\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
(
watchers
&&
forks
)
@cache
[
set
.
name
]
||=
{}
@cache
[
set
.
name
][
:github_watchers
]
=
watchers
@cache
[
set
.
name
][
:github_forks
]
=
forks
@cache
[
set
.
name
][
:github_check_date
]
=
Time
.
now
save_cache_file
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment