Class: GemMirror::Gem
- Inherits:
-
Object
- Object
- GemMirror::Gem
- Defined in:
- lib/gem_mirror/gem.rb
Overview
The Gem class contains data about a Gem such as the name, requirement as well as providing some methods to more easily extract the specific version number.
Instance Attribute Summary collapse
- #name ⇒ String readonly
- #requirement ⇒ Gem::Requirement readonly
Class Method Summary collapse
-
.version_for(requirement) ⇒ Gem::Version
Returns a ‘Gem::Version` instance based on the specified requirement.
Instance Method Summary collapse
-
#filename(gem_version = nil) ⇒ String
Returns the filename of the Gemfile.
-
#initialize(name, requirement = nil) ⇒ Gem
constructor
A new instance of Gem.
- #version ⇒ Gem::Version
- #version? ⇒ TrueClass|FalseClass
Constructor Details
#initialize(name, requirement = nil) ⇒ Gem
Returns a new instance of Gem.
31 32 33 34 35 36 37 38 |
# File 'lib/gem_mirror/gem.rb', line 31 def initialize(name, requirement = nil) requirement ||= ::Gem::Requirement.default requirement = ::Gem::Requirement.new(requirement) if requirement.is_a?(String) @name = name @requirement = requirement end |
Instance Attribute Details
#name ⇒ String (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gem_mirror/gem.rb', line 14 class Gem attr_reader :name, :requirement ## # Returns a `Gem::Version` instance based on the specified requirement. # # @param [Gem::Requirement] requirement # @return [Gem::Version] # def self.version_for(requirement) ::Gem::Version.new(requirement.requirements.max.last.version) end ## # @param [String] name # @param [Gem::Requirement] requirement # def initialize(name, requirement = nil) requirement ||= ::Gem::Requirement.default requirement = ::Gem::Requirement.new(requirement) if requirement.is_a?(String) @name = name @requirement = requirement end ## # @return [Gem::Version] # def version @version ||= self.class.version_for(requirement) end ## # @return [TrueClass|FalseClass] # def version? version && !version.segments.reject(&:zero?).empty? end ## # Returns the filename of the Gemfile. # # @param [String] gem_version # @return [String] # def filename(gem_version = nil) gem_version ||= version.to_s "#{name}-#{gem_version}.gem" end end |
#requirement ⇒ Gem::Requirement (readonly)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gem_mirror/gem.rb', line 14 class Gem attr_reader :name, :requirement ## # Returns a `Gem::Version` instance based on the specified requirement. # # @param [Gem::Requirement] requirement # @return [Gem::Version] # def self.version_for(requirement) ::Gem::Version.new(requirement.requirements.max.last.version) end ## # @param [String] name # @param [Gem::Requirement] requirement # def initialize(name, requirement = nil) requirement ||= ::Gem::Requirement.default requirement = ::Gem::Requirement.new(requirement) if requirement.is_a?(String) @name = name @requirement = requirement end ## # @return [Gem::Version] # def version @version ||= self.class.version_for(requirement) end ## # @return [TrueClass|FalseClass] # def version? version && !version.segments.reject(&:zero?).empty? end ## # Returns the filename of the Gemfile. # # @param [String] gem_version # @return [String] # def filename(gem_version = nil) gem_version ||= version.to_s "#{name}-#{gem_version}.gem" end end |
Class Method Details
.version_for(requirement) ⇒ Gem::Version
Returns a ‘Gem::Version` instance based on the specified requirement.
23 24 25 |
# File 'lib/gem_mirror/gem.rb', line 23 def self.version_for(requirement) ::Gem::Version.new(requirement.requirements.max.last.version) end |
Instance Method Details
#filename(gem_version = nil) ⇒ String
Returns the filename of the Gemfile.
60 61 62 63 64 |
# File 'lib/gem_mirror/gem.rb', line 60 def filename(gem_version = nil) gem_version ||= version.to_s "#{name}-#{gem_version}.gem" end |
#version ⇒ Gem::Version
43 44 45 |
# File 'lib/gem_mirror/gem.rb', line 43 def version @version ||= self.class.version_for(requirement) end |
#version? ⇒ TrueClass|FalseClass
50 51 52 |
# File 'lib/gem_mirror/gem.rb', line 50 def version? version && !version.segments.reject(&:zero?).empty? end |