Class: GemsBond::Gem

Inherits:
Object
  • Object
show all
Includes:
Examination, Helpers::ConcurrencyHelper
Defined in:
lib/gems_bond/gem.rb

Overview

Handles gem data

Constant Summary collapse

RUBY_GEM_KEYS =
%i[
  days_since_last_version downloads_count info last_version last_version_date source_code_uri versions
].freeze
GITHUB_KEYS =
%i[
  contributors_count days_since_last_commit forks_count last_commit_date open_issues_count stars_count
].freeze

Constants included from Examination

Examination::BOUNDARIES, Examination::RESULTS, Examination::SCORES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Examination

#activity_score, #average_score, #popularity_score

Methods included from Helpers::ConcurrencyHelper

#each_concurrently

Constructor Details

#initialize(dependency, unknown: false) ⇒ GemsBond::Gem

Initializes an instance

Parameters:

  • dependency (Bundler::Dependency)
  • unknown (Boolean) (defaults to: false)

    is it a current dependency?



28
29
30
31
# File 'lib/gems_bond/gem.rb', line 28

def initialize(dependency, unknown: false)
  @dependency = dependency
  @unknown = unknown
end

Instance Attribute Details

#unknownObject (readonly)

Returns the value of attribute unknown.



14
15
16
# File 'lib/gems_bond/gem.rb', line 14

def unknown
  @unknown
end

Instance Method Details

#descriptionString

Returns description

Returns:

  • (String)

    (memoized)



47
48
49
50
51
# File 'lib/gems_bond/gem.rb', line 47

def description
  memoize(__method__) do
    unknown ? info : @dependency.to_spec.description
  end
end

#exist?Boolean

Is the gem hosted on RubyGems?

Returns:

  • (Boolean)


35
36
37
# File 'lib/gems_bond/gem.rb', line 35

def exist?
  ruby_gems_fetcher.started?
end

#github_urlString?

Returns GitHub url if exist

Returns:

  • (String, nil)


77
78
79
80
81
# File 'lib/gems_bond/gem.rb', line 77

def github_url
  [homepage, source_code_uri].find do |url|
    GemsBond::Fetchers::Github.valid_url?(url)
  end
end

#homepageString

Returns homepage

Returns:

  • (String)

    (memoized)



63
64
65
66
67
# File 'lib/gems_bond/gem.rb', line 63

def homepage
  memoize(__method__) do
    @dependency.to_spec.homepage unless unknown
  end
end

#nameString

Returns name

Returns:

  • (String)

    (memoized)



41
42
43
# File 'lib/gems_bond/gem.rb', line 41

def name
  memoize(__method__) { @dependency.name }
end

#prepare_data(keys: nil, concurrency: false, verbose: false) ⇒ void

This method returns an undefined value.

Fetches data from APIs

Parameters:

  • concurrency (Boolean) (defaults to: false)

    should it be run concurrently?

  • verbose (Boolean) (defaults to: false)

    should gem’s name be stdout?



117
118
119
120
121
122
123
124
125
# File 'lib/gems_bond/gem.rb', line 117

def prepare_data(keys: nil, concurrency: false, verbose: false)
  fetch_key = ->(key) { (keys.nil? || key.in?(keys)) && __send__(key) }
  if concurrency
    each_concurrently(RUBY_GEM_KEYS + GITHUB_KEYS, &fetch_key)
  else
    (RUBY_GEM_KEYS + GITHUB_KEYS).each(&fetch_key)
  end
  puts(name) if verbose
end

#urlString

Returns url

Returns:

  • (String)


71
72
73
# File 'lib/gems_bond/gem.rb', line 71

def url
  homepage || source_code_uri
end

#versionString

Returns used version

Returns:

  • (String)

    (memoized)



55
56
57
58
59
# File 'lib/gems_bond/gem.rb', line 55

def version
  memoize(__method__) do
    @dependency.to_spec.version.to_s unless unknown
  end
end

#version_gapInteger?

Returns gap between installed and last released version, in days

Returns:

  • (Integer, nil)

    (memoized)



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gems_bond/gem.rb', line 101

def version_gap
  memoize(:version_gap) do
    return unless version && versions

    index = versions.index { |v| v[:number] == version }
    return unless index

    gap = versions[0..index].count { |v| !v[:prerelease] } - 1
    gap.positive? ? gap : 0
  end
end