Class: R10K::ModuleRepository::Forge

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/module_repository/forge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forge = 'forge.puppetlabs.com') ⇒ Forge

Returns a new instance of Forge.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/r10k/module_repository/forge.rb', line 19

def initialize(forge = 'forge.puppetlabs.com')
  @forge = forge

  @conn = Faraday.new(
    :url => "https://#{@forge}",
    :user_agent => "Ruby/r10k #{R10K::VERSION}"
  ) do |builder|
    builder.request :multi_json
    builder.response :multi_json

    # This needs to be _after_ request/response configuration for testing
    # purposes. This comment is the result of much consternation.
    builder.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#:conn(: conn) ⇒ Faraday (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Faraday)


17
# File 'lib/r10k/module_repository/forge.rb', line 17

attr_reader :conn

#connObject (readonly)

Returns the value of attribute conn.



17
18
19
# File 'lib/r10k/module_repository/forge.rb', line 17

def conn
  @conn
end

#forgeObject (readonly)

Returns the value of attribute forge.



12
13
14
# File 'lib/r10k/module_repository/forge.rb', line 12

def forge
  @forge
end

Instance Method Details

#latest_version(module_name) ⇒ String

Query for the newest published version of a module

Examples:

forge = R10K::ModuleRepository::Forge.new
forge.latest_version('adrien/boolean')
#=> "1.0.1"

Parameters:

  • module_name (String)

    The fully qualified module name

Returns:

  • (String)

    The latest published version of the given module



61
62
63
# File 'lib/r10k/module_repository/forge.rb', line 61

def latest_version(module_name)
  versions(module_name).last
end

#versions(module_name) ⇒ Array<String>

Query for all published versions of a module

Examples:

forge = R10K::ModuleRepository::Forge.new
forge.versions('adrien/boolean')
#=> ["0.9.0-rc1", "0.9.0", "1.0.0", "1.0.1"]

Parameters:

  • module_name (String)

    The fully qualified module name

Returns:

  • (Array<String>)

    All published versions of the given module



44
45
46
47
48
49
50
# File 'lib/r10k/module_repository/forge.rb', line 44

def versions(module_name)
  response = @conn.get("/api/v1/releases.json", {'module' => module_name})

  response.body[module_name].map do |version_info|
    version_info['version']
  end
end