Class: GemsBond::Gem
- Inherits:
-
Object
- Object
- GemsBond::Gem
- 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
-
#unknown ⇒ Object
readonly
Returns the value of attribute unknown.
Instance Method Summary collapse
-
#description ⇒ String
Returns description.
-
#exist? ⇒ Boolean
Is the gem hosted on RubyGems?.
-
#github_url ⇒ String?
Returns GitHub url if exist.
-
#homepage ⇒ String
Returns homepage.
-
#initialize(dependency, unknown: false) ⇒ GemsBond::Gem
constructor
Initializes an instance.
-
#name ⇒ String
Returns name.
-
#prepare_data(keys: nil, concurrency: false, verbose: false) ⇒ void
Fetches data from APIs.
-
#url ⇒ String
Returns url.
-
#version ⇒ String
Returns used version.
-
#version_gap ⇒ Integer?
Returns gap between installed and last released version, in days.
Methods included from Examination
#activity_score, #average_score, #popularity_score
Methods included from Helpers::ConcurrencyHelper
Constructor Details
#initialize(dependency, unknown: false) ⇒ GemsBond::Gem
Initializes an instance
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
#unknown ⇒ Object (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
#description ⇒ String
Returns description
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?
35 36 37 |
# File 'lib/gems_bond/gem.rb', line 35 def exist? ruby_gems_fetcher.started? end |
#github_url ⇒ String?
Returns GitHub url if exist
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 |
#homepage ⇒ String
Returns homepage
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 |
#name ⇒ String
Returns name
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
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 |
#url ⇒ String
Returns url
71 72 73 |
# File 'lib/gems_bond/gem.rb', line 71 def url homepage || source_code_uri end |
#version ⇒ String
Returns used version
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_gap ⇒ Integer?
Returns gap between installed and last released version, in days
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 |