Class: Ra10ke::Validate::Validation
- Inherits:
-
Object
- Object
- Ra10ke::Validate::Validation
- Includes:
- PuppetfileParser
- Defined in:
- lib/ra10ke/validate.rb
Instance Attribute Summary collapse
-
#puppetfile ⇒ Object
readonly
Returns the value of attribute puppetfile.
Instance Method Summary collapse
-
#all_modules ⇒ Array[Hash]
Array of module information and git status.
-
#bad_mods? ⇒ Boolean
-
true if there are any bad mods.
-
-
#initialize(file) ⇒ Validation
constructor
A new instance of Validation.
-
#sorted_mods ⇒ Hash
-
sorts the mods based on good/bad.
-
Methods included from PuppetfileParser
#forge_modules, #git_modules, #modules, #parse_module_args, #process_args
Constructor Details
#initialize(file) ⇒ Validation
Returns a new instance of Validation.
38 39 40 41 42 |
# File 'lib/ra10ke/validate.rb', line 38 def initialize(file) file ||= './Puppetfile' @puppetfile = File.(file) abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile) end |
Instance Attribute Details
#puppetfile ⇒ Object (readonly)
Returns the value of attribute puppetfile.
36 37 38 |
# File 'lib/ra10ke/validate.rb', line 36 def puppetfile @puppetfile end |
Instance Method Details
#all_modules ⇒ Array[Hash]
Returns array of module information and git status.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ra10ke/validate.rb', line 45 def all_modules @all_modules ||= begin r10k_branch = Ra10ke::GitRepo.current_branch(File.dirname(puppetfile)) git_modules(puppetfile).map do |mod| repo = Ra10ke::GitRepo.new(mod[:args][:git]) ref = mod[:args][:ref] || mod[:args][:tag] || mod[:args][:branch] || mod[:args][:commit] # If using control_branch, try to guesstimate what the target branch should be if ref == ':control_branch' ref = ENV['CONTROL_BRANCH'] \ || r10k_branch \ || mod[:args][:default_branch_override] \ || ENV['CONTROL_BRANCH_FALLBACK'] \ || mod[:args][:default_branch] \ || 'main' end valid_ref = repo.valid_ref?(ref) || repo.valid_commit?(mod[:args][:ref]) { name: mod[:name], url: repo.url, ref: ref, valid_url?: repo.valid_url?, valid_ref?: valid_ref, status: valid_ref ? Ra10ke::Validate::GOOD_EMOJI : Ra10ke::Validate::BAD_EMOJI } end end end |
#bad_mods? ⇒ Boolean
Returns - true if there are any bad mods.
74 75 76 |
# File 'lib/ra10ke/validate.rb', line 74 def bad_mods? all_modules.find_all { |mod| !mod[:valid_ref?] }.count > 0 end |
#sorted_mods ⇒ Hash
Returns - sorts the mods based on good/bad.
79 80 81 |
# File 'lib/ra10ke/validate.rb', line 79 def sorted_mods all_modules.sort_by { |a| a[:valid_ref?] ? 1 : 0 } end |