class DependencyInspector::RubyGemfile::Requirement

Constants

DEFAULT_REQUIREMENT
OPS
PATTERN
PATTERN_RAW
VERSION_PATTERN

Attributes

requirements[R]

Public Class Methods

create(requirements) click to toggle source
# File lib/dependency_inspector/ruby_gemfile/requirement.rb, line 35
def self.create(requirements)
  case requirements
  when RubyGemfile::Requirement then
    requirements
  when Array then
    new requirements
  else
    if input.respond_to? :to_str
      new [input.to_str]
    else
      default
    end
  end
end
default() click to toggle source
# File lib/dependency_inspector/ruby_gemfile/requirement.rb, line 50
def self.default
  new ['>= 0']
end
new(*requirements) click to toggle source
# File lib/dependency_inspector/ruby_gemfile/requirement.rb, line 23
def initialize(*requirements)
  requirements = requirements.flatten
  requirements.compact!
  requirements.uniq!

  if requirements.empty?
    @requirements = [DEFAULT_REQUIREMENT]
  else
    @requirements = requirements.map! { |r| self.class.parse r }
  end
end
parse(obj) click to toggle source
# File lib/dependency_inspector/ruby_gemfile/requirement.rb, line 54
def self.parse(obj)
  unless PATTERN =~ obj.to_s
    fail Exception, "Wrong requirement [#{obj.inspect}]"
  end

  if Regexp.last_match(1) == '>=' && Regexp.last_match(2) == '0'
    DEFAULT_REQUIREMENT
  else
    [Regexp.last_match(1) || '=', Regexp.last_match(2)]
  end
end