class Pod::Installer::Analyzer::SpecsState

This class represents the state of a collection of Pods.

@note The names of the pods stored by this class are always the root

name of the specification.

@note The motivation for this class is to ensure that the names of the

subspecs are added instead of the name of the Pods.

Attributes

added[R]

@return [Set<String>] the names of the pods that were added.

changed[R]

@return [Set<String>] the names of the pods that were changed.

deleted[R]

@return [Set<String>] the names of the pods that were deleted.

unchanged[R]

@return [Set<String>] the names of the pods that were unchanged.

Public Class Methods

new(pods_by_state = nil) click to toggle source

Initialize a new instance

@param [Hash{Symbol=>String}] pods_by_state

The name of the pods grouped by their state
(`:added`, `:removed`, `:changed` or `:unchanged`).
# File lib/cocoapods/installer/analyzer/specs_state.rb, line 37
def initialize(pods_by_state = nil)
  @added     = Set.new
  @deleted   = Set.new
  @changed   = Set.new
  @unchanged = Set.new

  if pods_by_state
    {
      :added => :added,
      :changed => :changed,
      :removed => :deleted,
      :unchanged => :unchanged,
    }.each do |state, spec_state|
      Array(pods_by_state[state]).each do |name|
        add_name(name, spec_state)
      end
    end
  end
end

Public Instance Methods

add_name(name, state) click to toggle source

Adds the name of a Pod to the give state.

@param [String] name

the name of the Pod.

@param [Symbol] state

the state of the Pod.

@return [void]

# File lib/cocoapods/installer/analyzer/specs_state.rb, line 82
def add_name(name, state)
  send(state) << Specification.root_name(name)
end
print() click to toggle source

Displays the state of each pod.

@return [void]

to_s(states: %i(added deleted changed unchanged)) click to toggle source
# File lib/cocoapods/installer/analyzer/specs_state.rb, line 68
def to_s(states: %i(added deleted changed unchanged))
  lines(states).join("\n")
end

Private Instance Methods

lines(states) click to toggle source

@return [Array<String>] A description of changes for the given states,

one per line
# File lib/cocoapods/installer/analyzer/specs_state.rb, line 91
def lines(states)
  prefixes = {
    :added     => 'A'.green,
    :deleted   => 'R'.red,
    :changed   => 'M'.yellow,
    :unchanged => '-',
  }

  states.flat_map do |state|
    send(state).sort.map do |pod|
      prefixes[state.to_sym] + " #{pod}"
    end
  end
end