Class: TenYearsRails::GemInfo
- Inherits:
-
Object
- Object
- TenYearsRails::GemInfo
- Includes:
- ActionView::Helpers::DateHelper
- Defined in:
- lib/ten_years_rails/gem_info.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NullGemInfo
Instance Attribute Summary collapse
-
#gem_specification ⇒ Object
readonly
Returns the value of attribute gem_specification.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #age ⇒ Object
- #compatible_with_rails?(rails_version: Gem::Version.new("5.0")) ⇒ Boolean
- #created_at ⇒ Object
- #from_rails? ⇒ Boolean
-
#initialize(gem_specification) ⇒ GemInfo
constructor
A new instance of GemInfo.
- #latest_version ⇒ Object
- #sourced_from_git? ⇒ Boolean
- #state(rails_version) ⇒ Object
- #unsatisfied_rails_dependencies(rails_version:) ⇒ Object
- #up_to_date? ⇒ Boolean
Constructor Details
#initialize(gem_specification) ⇒ GemInfo
Returns a new instance of GemInfo.
48 49 50 51 52 |
# File 'lib/ten_years_rails/gem_info.rb', line 48 def initialize(gem_specification) @gem_specification = gem_specification @version = gem_specification.version @name = gem_specification.name end |
Instance Attribute Details
#gem_specification ⇒ Object (readonly)
Returns the value of attribute gem_specification.
47 48 49 |
# File 'lib/ten_years_rails/gem_info.rb', line 47 def gem_specification @gem_specification end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
47 48 49 |
# File 'lib/ten_years_rails/gem_info.rb', line 47 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
47 48 49 |
# File 'lib/ten_years_rails/gem_info.rb', line 47 def version @version end |
Class Method Details
.all ⇒ Object
41 42 43 44 45 |
# File 'lib/ten_years_rails/gem_info.rb', line 41 def self.all Gem::Specification.each.map do |gem_specification| new(gem_specification) end end |
Instance Method Details
#age ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ten_years_rails/gem_info.rb', line 54 def age if respond_to?(:time_ago_in_words) "#{time_ago_in_words(created_at)} ago" else created_at.strftime("%b %e, %Y") end end |
#compatible_with_rails?(rails_version: Gem::Version.new("5.0")) ⇒ Boolean
97 98 99 |
# File 'lib/ten_years_rails/gem_info.rb', line 97 def compatible_with_rails?(rails_version: Gem::Version.new("5.0")) unsatisfied_rails_dependencies(rails_version: rails_version).empty? end |
#created_at ⇒ Object
66 67 68 |
# File 'lib/ten_years_rails/gem_info.rb', line 66 def created_at @created_at ||= gem_specification.date end |
#from_rails? ⇒ Boolean
109 110 111 |
# File 'lib/ten_years_rails/gem_info.rb', line 109 def from_rails? rails_gems.include?(name) end |
#latest_version ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ten_years_rails/gem_info.rb', line 86 def latest_version @latest_version ||= begin latest_gem_specification = Gem.latest_spec_for(name) if latest_gem_specification GemInfo.new(latest_gem_specification) else NullGemInfo.new end end end |
#sourced_from_git? ⇒ Boolean
62 63 64 |
# File 'lib/ten_years_rails/gem_info.rb', line 62 def sourced_from_git? !!gem_specification.git_version end |
#state(rails_version) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ten_years_rails/gem_info.rb', line 74 def state(rails_version) if compatible_with_rails?(rails_version: rails_version) :compatible elsif latest_version.compatible_with_rails?(rails_version: rails_version) :latest_compatible elsif latest_version.version == "NOT FOUND" :no_new_version else :incompatible end end |
#unsatisfied_rails_dependencies(rails_version:) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/ten_years_rails/gem_info.rb', line 101 def unsatisfied_rails_dependencies(rails_version:) rails_dependencies = gem_specification.runtime_dependencies.select {|dependency| rails_gems.include?(dependency.name) } rails_dependencies.reject do |rails_dependency| rails_dependency.requirement.satisfied_by?(Gem::Version.new(rails_version)) end end |
#up_to_date? ⇒ Boolean
70 71 72 |
# File 'lib/ten_years_rails/gem_info.rb', line 70 def up_to_date? version == latest_version.version end |