Class: Pod::Specification::Set::Statistics
- Inherits:
-
Object
- Object
- Pod::Specification::Set::Statistics
- Defined in:
- lib/cocoapods-core/specification/set/statistics.rb
Overview
The statistics class provides information about one or more Pod::Specification::Set that is not readily available because expensive to compute or provided by a remote source.
The class provides also facilities to work with a collection of sets. It always caches in memory the computed values and it can take an optional path to cache file that it is responsible of populating and invalidating.
To reuse the in memory cache and to minimize the disk access to the cache file a shared instance is also available.
Class Attribute Summary collapse
-
.instance ⇒ Statistics
The shared statistics instance.
Instance Attribute Summary collapse
-
#cache_expiration ⇒ Integer
The number of seconds after which the caches of values that might changed are discarded.
-
#cache_file ⇒ Pathname
The path to the optional cache file.
Accessing the statistics collapse
-
#creation_date(set) ⇒ Time
Computes the date in which the first podspec of a set was committed on its git source.
-
#creation_dates(sets) ⇒ Array<Time>
Computes the date in which the first podspec of each given set was committed on its git source.
-
#github_forks(set) ⇒ Integer
Computes the number of forks that a Pod has on Github.
-
#github_pushed_at(set) ⇒ Time
Computes the number of likes that a Pod has on Github.
-
#github_watchers(set) ⇒ Integer
Computes the number of likes that a Pod has on Github.
Instance Method Summary collapse
-
#initialize(cache_file = nil, cache_expiration = (60 * 60 * 24 * 3)) ⇒ Statistics
constructor
A new instance of Statistics.
Constructor Details
#initialize(cache_file = nil, cache_expiration = (60 * 60 * 24 * 3)) ⇒ Statistics
Returns a new instance of Statistics.
53 54 55 56 57 58 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 53 def initialize(cache_file = nil, cache_expiration = (60 * 60 * 24 * 3)) require 'yaml' @cache_file = cache_file @cache_expiration = cache_expiration end |
Class Attribute Details
.instance ⇒ Statistics
Returns the shared statistics instance.
19 20 21 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 19 def self.instance @instance ||= new end |
Instance Attribute Details
#cache_expiration ⇒ Integer
If not specified on initialization defaults to 3 days.
Returns the number of seconds after which the caches of values that might changed are discarded.
47 48 49 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 47 def cache_expiration @cache_expiration end |
#cache_file ⇒ Pathname
The cache file can be specified after initialization, but it has to be configured before requiring any value, otherwise it is ignored.
Returns the path to the optional cache file.
40 41 42 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 40 def cache_file @cache_file end |
Instance Method Details
#creation_date(set) ⇒ Time
The set should be generated with only the source that is analyzed. If there are more than one the first one is processed.
This method needs to traverse the git history of the repo and thus incurs in a performance hit.
Computes the date in which the first podspec of a set was committed on its git source.
80 81 82 83 84 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 80 def creation_date(set) date = compute_creation_date(set) save_cache date end |
#creation_dates(sets) ⇒ Array<Time>
@see creation_date
This method is optimized for multiple sets because it saves the cache file only once.
Computes the date in which the first podspec of each given set was committed on its git source.
101 102 103 104 105 106 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 101 def creation_dates(sets) dates = {} sets.each { |set| dates[set.name] = compute_creation_date(set) } save_cache dates end |
#github_forks(set) ⇒ Integer
Computes the number of forks that a Pod has on Github.
128 129 130 131 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 128 def github_forks(set) github_stats_if_needed(set) get_value(set, :gh_forks) end |
#github_pushed_at(set) ⇒ Time
Computes the number of likes that a Pod has on Github.
140 141 142 143 144 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 140 def github_pushed_at(set) github_stats_if_needed(set) string_time = get_value(set, :pushed_at) Time.parse(string_time) if string_time end |
#github_watchers(set) ⇒ Integer
Computes the number of likes that a Pod has on Github.
116 117 118 119 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 116 def github_watchers(set) github_stats_if_needed(set) get_value(set, :gh_watchers) end |