Class: Bundler::Alive::StatusCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bundler/alive/status_collection.rb

Overview

Collection of Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection = {}) ⇒ StatusCollection

Generates instance of StatusCollection

Parameters:



22
23
24
25
26
27
28
29
30
31
# File 'lib/bundler/alive/status_collection.rb', line 22

def initialize(collection = {})
  @collection = collection
  @statuses_values = collection.values || []

  @alive_size = _alive_size
  @unknown_size = _unknown_size
  @archived_size = _archived_size

  freeze
end

Instance Attribute Details

#alive_sizeObject (readonly)

Returns the value of attribute alive_size.



13
14
15
# File 'lib/bundler/alive/status_collection.rb', line 13

def alive_size
  @alive_size
end

#archived_sizeObject (readonly)

Returns the value of attribute archived_size.



13
14
15
# File 'lib/bundler/alive/status_collection.rb', line 13

def archived_size
  @archived_size
end

#unknown_sizeObject (readonly)

Returns the value of attribute unknown_size.



13
14
15
# File 'lib/bundler/alive/status_collection.rb', line 13

def unknown_size
  @unknown_size
end

Instance Method Details

#[](name) ⇒ Status

Fetch Status of name

Parameters:

  • name (String)

Returns:



40
41
42
# File 'lib/bundler/alive/status_collection.rb', line 40

def [](name)
  collection[name]
end

#add(name, status) ⇒ StatusCollection

Add status

Parameters:

  • name (String)
  • status (Status)

Returns:



61
62
63
64
65
# File 'lib/bundler/alive/status_collection.rb', line 61

def add(name, status)
  collection[name] = status

  self.class.new(collection)
end

#all_alive?Boolean

All of statuses are alive nor not

Returns:

  • (Boolean)


101
102
103
# File 'lib/bundler/alive/status_collection.rb', line 101

def all_alive?
  collection.find { |_name, status| !!!status.alive || status.unknown? }.nil?
end

#archived_gemsObject



88
89
90
# File 'lib/bundler/alive/status_collection.rb', line 88

def archived_gems
  collection.find_all { |_name, gem| !!!gem.alive }
end

#merge(collection) ⇒ StatusCollection

Merge collection

Parameters:

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/bundler/alive/status_collection.rb', line 74

def merge(collection)
  return self.class.new(self.collection) if collection.nil?

  collection.each do |k, v|
    self.collection[k] = v
  end

  self.class.new(self.collection)
end

#namesArray<String>

Names of gems

Returns:

  • (Array<String>)


49
50
51
# File 'lib/bundler/alive/status_collection.rb', line 49

def names
  values.map(&:name)
end

#to_hObject



84
85
86
# File 'lib/bundler/alive/status_collection.rb', line 84

def to_h
  collection.transform_values(&:to_h)
end

#total_sizeInteger

Total size of collection

Returns:

  • (Integer)


110
111
112
# File 'lib/bundler/alive/status_collection.rb', line 110

def total_size
  collection.size
end

#unknown_gemsObject



92
93
94
# File 'lib/bundler/alive/status_collection.rb', line 92

def unknown_gems
  collection.find_all { |_name, gem| gem.unknown? }
end