Module: CompactIndex

Defined in:
lib/compact_index.rb,
lib/compact_index/gem.rb,
lib/compact_index/version.rb,
lib/compact_index/dependency.rb,
lib/compact_index/gem_version.rb,
lib/compact_index/versions_file.rb

Defined Under Namespace

Classes: Dependency, Gem, GemVersion, VersionsFile

Constant Summary collapse

VERSION =
"0.15.0"

Class Method Summary collapse

Class Method Details

.info(versions) ⇒ String

Formats the versions information of a gem, to be display in the /info/gemname endpoint.

Parameters:

  • versions_file (CompactIndex::VersionsFile)

    which will be used as a base response

  • gems (Array)

    an optional list of [CompactIndex::Gem] to be appended on the end of the base file. Example:

    [
      CompactIndex::GemVersion.new("1.0.1", "ruby", "abc123", "info123", [
        CompactIndex::Dependency.new("foo", "=1.0.1", "abc123"),
        CompactIndex::Dependency.new("bar", ">1.0, <2.0", "abc123"),
      ])
    ]
    

Returns:

  • (String)

    The formatted output. Example:

    --
    1.0.1 requirement:<2.0&>1.0|checksum:abc1
    1.0.2 requirement:<2.0&>1.0,requirement2:=1.1|checksum:abc2,ruby:>1.0,rubygems:>2.0
    


72
73
74
75
76
# File 'lib/compact_index.rb', line 72

def self.info(versions)
  versions.inject(+"---\n") do |output, version|
    output << version.to_line << "\n"
  end
end

.names(gem_names) ⇒ String

Formats a list of gem names, to be used on the /names endpoint.

Parameters:

  • gem_names (Array)

    array with gem names to be formatted, in alphabetical order

Returns:

  • (String)

    names on the specified format for new index /names endpoint. Example:

    ---
    rack
    rails
    other-gem
    


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

def self.names(gem_names)
  gem_names.join("\n").prepend("---\n") << "\n"
end

.versions(versions_file, gems = nil, args = {}) ⇒ String

Returns the versions file content argumented with some extra gems

Parameters:

  • versions_file (CompactIndex::VersionsFile)

    which will be used as a base response

  • gems (Array) (defaults to: nil)

    an optional list of [CompactIndex::Gem] to be appended on the end of the base file. Example:

    [
      CompactIndex::Gem.new("gem1", [
        CompactIndex::GemVersion.new("0.9.8", "ruby", "abc123"),
        CompactIndex::GemVersion.new("0.9.9", "jruby", "abc123"),
      ]),
      CompactIndex::Gem.new("gem2", [
        CompactIndex::GemVersion.new("0.9.8", "ruby", "abc123"),
        CompactIndex::GemVersion.new("0.9.9", "jruby", "abc123"),
      ])
    ]
    

Returns:

  • (String)

    The formatted output. Example:

    created_at: 2001-01-01T01:01:01-01:01
    ---
    rack 0.1.0,0.1.1,0.1.2,0.2.0,0.2.1,0.3.0,0.4.0,0.4.1,0.5.0,0.5.1,0.5.2,0.5.3 c54e4b7e14861a5d8c225283b75075f4
    rails 0.0.1,0.1.0 00fd5c36764f4ec1e8adf1c9adaada55
    sinatra 0.1.1,0.1.2,0.1.3 46f0a24d291725736216b4b6e7412be6
    


48
49
50
# File 'lib/compact_index.rb', line 48

def self.versions(versions_file, gems = nil, args = {})
  versions_file.contents(gems, args)
end