Class: Pod::Specification::Set::Statistics

Inherits:
Object
  • Object
show all
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 Attribute Summary collapse

Accessing the statistics collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_file = nil, cache_expiration = (60 * 60 * 24 * 3)) ⇒ Statistics

Returns a new instance of Statistics.

Parameters:

  • cache_file (Pathname) (defaults to: nil)

    @see cache_file

  • cache_expiration (Integer) (defaults to: (60 * 60 * 24 * 3))

    @see cache_expiration



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

.instanceStatistics

Returns the shared statistics instance.

Returns:

  • (Statistics)

    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_expirationInteger

Note:

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.

Returns:

  • (Integer)

    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_filePathname

Note:

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.

Returns:

  • (Pathname)

    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

Note:

The set should be generated with only the source that is analyzed. If there are more than one the first one is processed.

Note:

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.

Parameters:

  • set (Set)

    the set for the Pod whose creation date is needed.

Returns:

  • (Time)

    the date in which a Pod appeared for the first time on the Pod::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>

Note:

@see creation_date

Note:

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.

Parameters:

  • sets (Array<Set>)

    the list of the sets for the Pods whose creation date is needed.

Returns:

  • (Array<Time>)

    the list of the dates in which the Pods appeared for the first time on the Pod::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.

Parameters:

  • set (Set)

    @see github_watchers

Returns:

  • (Integer)

    the number of forks or nil if the Pod is not hosted 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.

Parameters:

  • set (Set)

    @see github_watchers

Returns:

  • (Time)

    the time of the last push or nil if the Pod is not hosted 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.

Parameters:

  • set (Set)

    the set of the Pod.

Returns:

  • (Integer)

    the number of likes or nil if the Pod is not hosted 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