Class: Ra10ke::Deprecation::Validation

Inherits:
Object
  • Object
show all
Includes:
PuppetfileParser
Defined in:
lib/ra10ke/deprecation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



34
35
36
37
38
# File 'lib/ra10ke/deprecation.rb', line 34

def initialize(file)
  file ||= './Puppetfile'
  @puppetfile = File.expand_path(file)
  abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile)
end

Instance Attribute Details

#puppetfileObject (readonly)

Returns the value of attribute puppetfile.



32
33
34
# File 'lib/ra10ke/deprecation.rb', line 32

def puppetfile
  @puppetfile
end

Instance Method Details

#bad_mods?Boolean

Returns - true if there are any bad mods.

Returns:

  • (Boolean)
    • true if there are any bad mods



63
64
65
# File 'lib/ra10ke/deprecation.rb', line 63

def bad_mods?
  deprecated_modules.any?
end

#deprecated_modulesArray[Hash]

Returns array of module information and git status.

Returns:

  • (Array[Hash])

    array of module information and git status



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ra10ke/deprecation.rb', line 41

def deprecated_modules
  @deprecated_modules ||= begin
    deprecated = forge_modules(puppetfile).map do |mod|
      # For Ruby 2.4 support
      begin # rubocop:disable Style/RedundantBegin
        module_name = "#{mod[:namespace] || mod[:name]}-#{mod[:name]}"
        forge_data = PuppetForge::Module.find(module_name)

        next forge_data if forge_data.deprecated_at

        nil
      rescue Faraday::ResourceNotFound
        nil
      end
    end
    deprecated.compact.map do |mod|
      { name: mod.slug, deprecated_at: Time.parse(mod.deprecated_at) }
    end
  end
end

#sorted_modsHash

Returns - sorts the mods based on good/bad.

Returns:

  • (Hash)
    • sorts the mods based on good/bad



68
69
70
# File 'lib/ra10ke/deprecation.rb', line 68

def sorted_mods
  deprecated_modules.sort_by { |a| a[:name] }
end