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.
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.
Class Method Summary collapse
-
.instance ⇒ Statistics
The shared statistics instance.
-
.instance=(instance) ⇒ Statistics
Allows to set the shared instance.
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.
55 56 57 58 59 60 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 55 def initialize(cache_file = nil, cache_expiration = (60 * 60 * 24 * 3)) require 'yaml' @cache_file = cache_file @cache_expiration = cache_expiration 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.
49 50 51 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 49 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.
42 43 44 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 42 def cache_file @cache_file end |
Class Method Details
.instance ⇒ Statistics
Returns the shared statistics instance.
21 22 23 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 21 def self.instance @instance ||= new end |
.instance=(instance) ⇒ Statistics
Allows to set the shared instance.
32 33 34 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 32 def self.instance=(instance) @instance = instance 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.
82 83 84 85 86 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 82 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.
103 104 105 106 107 108 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 103 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.
130 131 132 133 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 130 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.
142 143 144 145 146 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 142 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.
118 119 120 121 |
# File 'lib/cocoapods-core/specification/set/statistics.rb', line 118 def github_watchers(set) github_stats_if_needed(set) get_value(set, :gh_watchers) end |