Class: Pod::Requirement

Inherits:
Vendor::Gem::Requirement show all
Defined in:
lib/cocoapods-core/requirement.rb

Overview

TODO:

Move support about external sources and head information here from the Dependency class.

A Requirement is a set of one or more version restrictions of a Dependency.

It is based on the RubyGems class adapted to support CocoaPods specific information.

Constant Summary collapse

PATTERN =

Returns The regular expression used to validate input strings.

Returns:

  • (Regexp)

    The regular expression used to validate input strings.

/\A\s*(#{quoted_operators})?\s*(#{Version::VERSION_PATTERN})\s*\z/

Constants inherited from Vendor::Gem::Requirement

Vendor::Gem::Requirement::DefaultRequirement, Vendor::Gem::Requirement::OPS, Vendor::Gem::Requirement::PATTERN_RAW, Vendor::Gem::Requirement::SOURCE_SET_REQUIREMENT

Instance Attribute Summary

Attributes inherited from Vendor::Gem::Requirement

#requirements

Class Method Summary collapse

Methods inherited from Vendor::Gem::Requirement

#==, #as_list, #concat, #encode_with, #exact?, #fix_syck_default_key_in_requirements, #for_lockfile, #hash, #init_with, #initialize, #marshal_dump, #marshal_load, #none?, #prerelease?, #pretty_print, #satisfied_by?, source_set, #specific?, #to_s, #to_yaml_properties, #yaml_initialize

Constructor Details

This class inherits a constructor from Pod::Vendor::Gem::Requirement

Class Method Details

.create(input) ⇒ Requirement

Factory method to create a new requirement.

Parameters:

Returns:


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cocoapods-core/requirement.rb', line 27

def self.create(input)
  case input
  when Requirement
    input
  when Version, Array
    new(input)
  else
    if input.respond_to? :to_str
      new([input.to_str])
    else
      default
    end
  end
end

.defaultRequirement

Returns The default requirement.

Returns:


44
45
46
# File 'lib/cocoapods-core/requirement.rb', line 44

def self.default
  new('>= 0')
end

.parse(input) ⇒ Array

Parses the given object returning a tuple where the first entry is an operator and the second a version. If not operator is provided it defaults to =.

Parameters:

  • input (String, Version)

    The input passed to create the requirement.

Returns:

  • (Array)

    A tuple representing the requirement.


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods-core/requirement.rb', line 57

def self.parse(input)
  return ['=', input] if input.is_a?(Version)

  unless PATTERN =~ input.to_s
    raise ArgumentError, "Illformed requirement `#{input.inspect}`"
  end

  operator = Regexp.last_match[1] || '='
  version = Version.new(Regexp.last_match[2])
  [operator, version]
end