Class: Composer::Package::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/composer/package/link.rb

Overview

Represents a link between two packages, represented by their names

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, constraint = nil, description = 'relates to', pretty_constraint = nil) ⇒ Link

Creates a new package link.

Parameters:

  • string

    source

  • string

    target

  • LinkConstraintInterface

    constraint Constraint applying to the target of this link

  • string

    description Used to create a descriptive string representation

  • string

    prettyConstraint



26
27
28
29
30
31
32
# File 'lib/composer/package/link.rb', line 26

def initialize(source, target, constraint = nil, description = 'relates to', pretty_constraint = nil)
  @source = source.downcase
  @target = target.downcase
  @constraint = constraint
  @description = description
  @pretty_constraint = pretty_constraint
end

Instance Attribute Details

#constraintObject (readonly)

Returns the value of attribute constraint.



18
19
20
# File 'lib/composer/package/link.rb', line 18

def constraint
  @constraint
end

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/composer/package/link.rb', line 18

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



18
19
20
# File 'lib/composer/package/link.rb', line 18

def target
  @target
end

Instance Method Details

#pretty_constraintObject



34
35
36
37
38
39
# File 'lib/composer/package/link.rb', line 34

def pretty_constraint
  unless @pretty_constraint
    raise UnexpectedValueError, "Link #{self} has been misconfigured and had no pretty constraint given."
  end
  @pretty_constraint
end

#pretty_string(source_package) ⇒ Object



41
42
43
# File 'lib/composer/package/link.rb', line 41

def pretty_string(source_package)
  "#{source_package.pretty_string} #{@description} #{@target} #{@constraint.pretty_string}"
end

#to_sObject



45
46
47
# File 'lib/composer/package/link.rb', line 45

def to_s
  "#{@source} #{@description} #{@target} (#{@constraint})"
end