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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
36 deletions
+104
-36
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
+55
-25
No files found.
lib/cocoapods/command/list.rb
View file @
cf3bcecb
...
@@ -37,10 +37,13 @@ module Pod
...
@@ -37,10 +37,13 @@ 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
.
each
do
|
set
|
sets
=
Source
.
all_sets
set_date
=
Pod
::
Specification
::
Statistics
.
new
(
set
).
creation_date
creation_dates
=
Pod
::
Specification
::
Statistics
.
instance
.
creation_dates
(
sets
)
sets
.
each
do
|
set
|
set_date
=
creation_dates
[
set
.
name
]
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
]
groups
[
d
]
<<
set
groups
[
d
]
<<
set
break
break
...
@@ -52,7 +55,7 @@ module Pod
...
@@ -52,7 +55,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
.
sort_by
{
|
set
|
Pod
::
Specification
::
Statistics
.
new
(
set
).
creation_date
})
@presenter
.
present_sets
(
sets
.
sort_by
{
|
set
|
creation_dates
[
set
.
name
]
})
end
end
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
module
Pod
class
Command
class
Command
class
Presenter
class
Presenter
...
@@ -15,16 +49,17 @@ module Pod
...
@@ -15,16 +49,17 @@ 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
(
s
tats
.
summary
)
puts
wrap_string
(
s
et
.
summary
)
puts_detail
(
'Homepage'
,
s
tats
.
homepage
)
puts_detail
(
'Homepage'
,
s
et
.
homepage
)
puts_detail
(
'Source'
,
s
tats
.
source_url
)
puts_detail
(
'Source'
,
s
et
.
source_url
)
puts_detail
(
'Watchers'
,
s
tats
.
github_watchers
)
if
@stats
puts_detail
(
'Watchers'
,
s
et
.
github_watchers
)
if
@stats
puts_detail
(
'Forks'
,
s
tats
.
github_forks
)
if
@stats
puts_detail
(
'Forks'
,
s
et
.
github_forks
)
if
@stats
puts
puts
end
end
private
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
def
wrap_string
(
txt
,
col
=
80
,
indentation
=
4
)
def
wrap_string
(
txt
,
col
=
80
,
indentation
=
4
)
indent
=
' '
*
indentation
indent
=
' '
*
indentation
...
...
lib/cocoapods/source.rb
View file @
cf3bcecb
...
@@ -13,7 +13,7 @@ module Pod
...
@@ -13,7 +13,7 @@ module Pod
end
end
def
all_sets
def
all_sets
all
.
map
!
{
|
source
|
source
.
pod_sets
}.
flatten
all
.
map
{
|
source
|
source
.
pod_sets
}.
flatten
end
end
def
search
(
dependency
)
def
search
(
dependency
)
...
...
lib/cocoapods/specification/statistics.rb
View file @
cf3bcecb
require
'net/http'
require
'net/http'
require
'yaml'
module
Pod
module
Pod
class
Specification
class
Specification
class
Statistics
class
Statistics
def
initialize
(
set
)
include
Config
::
Mixin
@set
=
set
@spec
=
set
.
specification
.
part_of_other_pod?
?
set
.
specification
.
part_of_specification
:
set
.
specification
def
self
.
instance
@instance
||=
new
end
end
def
creation_date
def
self
.
instance
=
(
instance
)
Dir
.
chdir
(
@set
.
pod_dir
.
dirname
)
do
@instance
=
instance
@creation_date
||=
Time
.
at
(
`git log --format=%ct ./
#{
@set
.
name
}
| tail -1`
.
to_i
)
end
end
end
def
homepag
e
def
initializ
e
@
spec
.
homepage
@
cache
=
cache_file
.
exist?
?
YAML
::
load
(
cache_file
.
read
)
:
{}
end
end
def
description
def
creation_dates
(
sets
)
@spec
.
description
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
end
def
summary
def
github_watchers
(
set
)
@spec
.
summary
compute_github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_watchers
]
if
@cache
[
set
.
name
]
end
end
def
source_url
def
github_forks
(
set
)
@spec
.
source
.
reject
{
|
k
,
_
|
k
==
:commit
||
k
==
:tag
}.
values
.
first
compute_github_stats_if_needed
(
set
)
@cache
[
set
.
name
][
:github_forks
]
if
@cache
[
set
.
name
]
end
end
def
github_response
private
return
@github_response
if
@github_response
github_url
,
username
,
reponame
=
*
(
source_url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
def
cache_file
if
github_url
Config
.
instance
.
repos_dir
+
'statistics.yml'
@github_response
=
Net
::
HTTP
.
get
(
'github.com'
,
"/api/v2/json/repos/show/
#{
username
}
/
#{
reponame
}
"
)
end
end
end
def
github_watchers
def
save_cache_file
github_response
.
match
(
/\"watchers\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
github_response
File
.
open
(
cache_file
,
'w'
)
{
|
f
|
f
.
write
(
YAML
::
dump
(
@cache
))
}
end
end
def
github_forks
def
compute_creation_date
(
set
)
github_response
.
match
(
/\"forks\"\W*:\W*([0-9]+)/
).
to_a
[
1
]
if
github_response
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
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
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