Class: NeetoCompliance::GemsVerifierBase

Inherits:
Base
  • Object
show all
Defined in:
lib/neeto_compliance/verifiers/gems_verifier_base.rb

Direct Known Subclasses

NeetoGemsVerifier

Instance Method Summary collapse

Methods inherited from Base

#app_is_exception?, #app_name, #apps_exception_list, #audit, #auto_correct!, #autofix_suggestion, #error_message, #print_description, #process, #verifier_name

Instance Method Details

#_latest_versionsObject



13
14
15
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 13

def _latest_versions
  JSON.parse(Net::HTTP.get_response(URI("https://neeto-library-stable-versions.herokuapp.com/versions")).body)
end

#autofix_commandObject



30
31
32
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 30

def autofix_command
  "bundle update #{@failed_gems.join(' ')}"
end

#find_latest_version(gem_name) ⇒ Object



39
40
41
42
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 39

def find_latest_version(gem_name)
  gem = latest_versions.find { |gem| gem["name"] == gem_name } || {}
  gem["released_version"]
end

#gemsObject



5
6
7
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 5

def gems
  []
end

#latest_versionsObject



9
10
11
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 9

def latest_versions
  @_latest_versions ||= _latest_versions
end

#load_current_versionsObject



34
35
36
37
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 34

def load_current_versions
  @current_versions = {}
  Bundler.load.specs.each { |gem| @current_versions[gem.name] = gem.version.to_s }
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/neeto_compliance/verifiers/gems_verifier_base.rb', line 17

def valid?
  @failed_gems = []
  load_current_versions
  gems.map do |gem|
    gv = GemVersionVerifier.new(@current_versions[gem[:name]], find_latest_version(gem[:name]), gem[:name])
    unless gv.valid?
      @failed_gems << gem[:name]
    end
  end

  @failed_gems.empty?
end