Class: Outdated::RubyGems::Gem
- Inherits:
-
Object
- Object
- Outdated::RubyGems::Gem
- Defined in:
- lib/outdated/ruby_gems/gem.rb
Instance Attribute Summary collapse
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #first ⇒ Object
- #get(version) ⇒ Object
-
#initialize(specs = []) ⇒ Gem
constructor
A new instance of Gem.
- #name ⇒ Object
- #recommend(currently_used_spec, cut_off) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(specs = []) ⇒ Gem
Returns a new instance of Gem.
14 15 16 17 18 |
# File 'lib/outdated/ruby_gems/gem.rb', line 14 def initialize(specs = []) @specs = specs raise ArgumentError, "conflicting spec names" unless specs.uniq(&:name).count < 2 end |
Instance Attribute Details
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
12 13 14 |
# File 'lib/outdated/ruby_gems/gem.rb', line 12 def specs @specs end |
Class Method Details
.from_response(name, response) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/outdated/ruby_gems/gem.rb', line 4 def self.from_response(name, response) return new if response.code == 404 body = response.body specs = JSON.parse(body).map { |spec| Outdated::RubyGems::Spec.from_response_object(name, spec) } new(specs) end |
Instance Method Details
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/outdated/ruby_gems/gem.rb', line 24 def empty? specs.empty? end |
#first ⇒ Object
32 33 34 |
# File 'lib/outdated/ruby_gems/gem.rb', line 32 def first specs.first end |
#get(version) ⇒ Object
36 37 38 |
# File 'lib/outdated/ruby_gems/gem.rb', line 36 def get(version) specs.find { |spec| spec.version == version } end |
#name ⇒ Object
20 21 22 |
# File 'lib/outdated/ruby_gems/gem.rb', line 20 def name specs.first.name end |
#recommend(currently_used_spec, cut_off) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/outdated/ruby_gems/gem.rb', line 40 def recommend(currently_used_spec, cut_off) recommended_spec = specs.find do |spec| semver = spec.version.to_s.split(/\./).map(&:to_i) currently_used_semver = currently_used_spec.version.to_s.split(/\./).map(&:to_i) prerelease = spec.prerelease too_new = cut_off < spec.created_at minor_or_major_upgrade = semver[0] > currently_used_semver[0] || semver[1] > currently_used_semver[1] !prerelease && !too_new && !minor_or_major_upgrade end code = if recommended_spec.nil? Outdated::IMMATURE elsif recommended_spec > currently_used_spec Outdated::OUTDATED elsif recommended_spec < currently_used_spec Outdated::IMMATURE end [recommended_spec, code] end |
#size ⇒ Object
28 29 30 |
# File 'lib/outdated/ruby_gems/gem.rb', line 28 def size specs.size end |