class DependencyChecker::ForgeHelper

Helper class for fetching data from the Forge and perform some basic operations

Public Class Methods

new(cache = {}) click to toggle source
# File lib/dependency_checker/forge_helper.rb, line 6
def initialize(cache = {})
  @cache = cache
end

Public Instance Methods

check_module_deprecated(module_name) click to toggle source

Check if a module is deprecated from data fetched from the Forge @return [Boolean] boolean result stating whether module is deprecated

# File lib/dependency_checker/forge_helper.rb, line 46
def check_module_deprecated(module_name)
  module_name = module_name.sub('/', '-')
  module_data = get_module_data(module_name)
  version = get_current_version(module_name)
  version.to_s.eql?('999.999.999') || version.to_s.eql?('99.99.99') || !module_data.attribute('deprecated_at').nil?
end
check_module_exists(module_name) click to toggle source

Retrieve module from Forge @return [PuppetForge::Module]

# File lib/dependency_checker/forge_helper.rb, line 40
def check_module_exists(module_name)
  !get_module_data(module_name).nil?
end
get_current_version(module_name) click to toggle source

Retrieve current version of module @return [SemanticPuppet::Version]

# File lib/dependency_checker/forge_helper.rb, line 12
def get_current_version(module_name)
  module_name = module_name.sub('/', '-')
  version = nil
  version = get_version(@cache[module_name]) if @cache.key?(module_name)

  unless version
    version = get_version(get_module_data(module_name)) if check_module_exists(module_name)
  end

  version
end
get_module_data(module_name) click to toggle source

Retrieve module data from Forge @return [Hash] Hash containing JSON response from Forge

# File lib/dependency_checker/forge_helper.rb, line 26
def get_module_data(module_name)
  module_name = module_name.sub('/', '-')
  module_data = @cache[module_name]
  begin
    @cache[module_name] = module_data = PuppetForge::Module.find(module_name) unless module_data
  rescue Faraday::ClientError
    return nil
  end

  module_data
end

Private Instance Methods

get_version(module_data) click to toggle source
# File lib/dependency_checker/forge_helper.rb, line 55
def get_version(module_data)
  SemanticPuppet::Version.parse(module_data.current_release.version)
end