Class: Geminabox::GemVersionCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/geminabox/gem_version_collection.rb

Overview

This class represents a sorted collection of Geminabox::GemVersion objects. It it used widely throughout the system for displaying and filtering gems.

Instance Method Summary collapse

Constructor Details

#initialize(initial_gems = []) ⇒ GemVersionCollection

Array of Geminabox::GemVersion objects, or an array of [name, version, platform] triples.



12
13
14
15
16
# File 'lib/geminabox/gem_version_collection.rb', line 12

def initialize(initial_gems=[])
  @gems = initial_gems.map{|object|
    coerce_to_gem_version(object)
  }.sort
end

Instance Method Details

#by_name(&block) ⇒ Object

The collection can contain gems of different names, this method groups them by name, and then sorts the different version of each name by version and platform.

yields ‘foo_gem’, version_collection



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/geminabox/gem_version_collection.rb', line 43

def by_name(&block)
  @grouped ||= @gems.group_by(&:name).map{|name, collection|
    [name, Geminabox::GemVersionCollection.new(collection)]
  }.sort_by{|name, collection|
    name.downcase
  }

  if block_given?
    @grouped.each(&block)
  else
    @grouped
  end
end

#each(&block) ⇒ Object



34
35
36
# File 'lib/geminabox/gem_version_collection.rb', line 34

def each(&block)
  @gems.each(&block)
end

#newestObject

FIXME: Terminology makes no sense when the version are not all of the same name



26
27
28
# File 'lib/geminabox/gem_version_collection.rb', line 26

def newest
  @gems.last
end

#oldestObject

FIXME: Terminology makes no sense when the version are not all of the same name



20
21
22
# File 'lib/geminabox/gem_version_collection.rb', line 20

def oldest
  @gems.first
end

#sizeObject



30
31
32
# File 'lib/geminabox/gem_version_collection.rb', line 30

def size
  @gems.size
end