Class: DependencyChecker::ForgeHelper
- Inherits:
-
Object
- Object
- DependencyChecker::ForgeHelper
- Defined in:
- lib/dependency_checker/forge_helper.rb
Instance Method Summary collapse
-
#check_module_deprecated(module_name) ⇒ Boolean
Check if a module is deprecated from data fetched from the Forge.
-
#check_module_exists(module_name) ⇒ PuppetForge::Module
Retrieve module from Forge.
-
#get_current_version(module_name) ⇒ SemanticPuppet::Version
Retrieve current version of module.
-
#get_module_data(module_name) ⇒ Hash
Retrieve module data from Forge.
-
#initialize(cache = {}, forge_hostname = nil, forge_token = nil) ⇒ ForgeHelper
constructor
A new instance of ForgeHelper.
-
#modules_in_namespace(namespace, endorsement = nil) ⇒ Array
Gets a list of all modules in a namespace, optionally filtered by endorsement.
Constructor Details
#initialize(cache = {}, forge_hostname = nil, forge_token = nil) ⇒ ForgeHelper
Returns a new instance of ForgeHelper.
9 10 11 12 13 |
# File 'lib/dependency_checker/forge_helper.rb', line 9 def initialize(cache = {}, forge_hostname = nil, forge_token = nil) @cache = cache PuppetForge.host = forge_hostname unless forge_hostname.nil? PuppetForge::Connection. = forge_token unless forge_token.nil? end |
Instance Method Details
#check_module_deprecated(module_name) ⇒ Boolean
Check if a module is deprecated from data fetched from the Forge
49 50 51 52 53 54 |
# File 'lib/dependency_checker/forge_helper.rb', line 49 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) ⇒ PuppetForge::Module
Retrieve module from Forge
43 44 45 |
# File 'lib/dependency_checker/forge_helper.rb', line 43 def check_module_exists(module_name) !get_module_data(module_name).nil? end |
#get_current_version(module_name) ⇒ SemanticPuppet::Version
Retrieve current version of module
17 18 19 20 21 22 23 24 25 |
# File 'lib/dependency_checker/forge_helper.rb', line 17 def get_current_version(module_name) module_name = module_name.sub('/', '-') version = nil version = get_version(@cache[module_name]) if @cache.key?(module_name) version = get_version(get_module_data(module_name)) if !version && check_module_exists(module_name) version end |
#get_module_data(module_name) ⇒ Hash
Retrieve module data from Forge
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dependency_checker/forge_helper.rb', line 29 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 StandardError return nil end module_data end |
#modules_in_namespace(namespace, endorsement = nil) ⇒ Array
Gets a list of all modules in a namespace, optionally filtered by endorsement.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/dependency_checker/forge_helper.rb', line 60 def modules_in_namespace(namespace, endorsement = nil) modules = PuppetForge::Module.where( owner: namespace, # rubocop:disable Layout/FirstArgumentIndentation hide_deprecated: true, module_groups: 'base pe_only', endorsements: endorsement ) raise "No modules found for #{namespace}." if modules.total.zero? modules.unpaginated.map(&:slug) end |