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/
DefaultRequirement =

rubocop:disable Naming/ConstantName

['>=', Version.new(0)]

Constants inherited from Vendor::Gem::Requirement

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

Instance Method Summary collapse

Methods inherited from Vendor::Gem::Requirement

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

Constructor Details

#initialize(*requirements) ⇒ Requirement

Note:

Duplicate requirements are ignored.

Note:

An empty set of ‘requirements` is the same as `“>= 0”`

Constructs a requirement from ‘requirements`.

Parameters:

  • requirements (String, Version, Array<String>, Array<Version>)

    The set of requirements



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cocoapods-core/requirement.rb', line 80

def initialize(*requirements)
  requirements = requirements.flatten
  requirements.compact!
  requirements.uniq!

  @requirements = if requirements.empty?
                    [DefaultRequirement]
                  else
                    requirements.map! { |r| self.class.parse r }
                  end
end

Class Method Details

.create(input) ⇒ Requirement

Factory method to create a new requirement.

Parameters:

Returns:



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

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:



46
47
48
# File 'lib/cocoapods-core/requirement.rb', line 46

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.



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

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

Instance Method Details

#none?Boolean

Returns true if this pod has no requirements.

Returns:

  • (Boolean)

    true if this pod has no requirements.



95
96
97
98
99
100
101
# File 'lib/cocoapods-core/requirement.rb', line 95

def none?
  if @requirements.size == 1
    @requirements[0] == DefaultRequirement
  else
    false
  end
end