Class: GemEnforcer::Setup::Validate

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_enforcer/setup/validate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, **params) ⇒ Validate

Returns a new instance of Validate.



11
12
13
14
15
16
# File 'lib/gem_enforcer/setup/validate.rb', line 11

def initialize(name:, **params)
  @params = params
  @gem_name = name
  @behaviors = []
  @errors = []
end

Instance Attribute Details

#behaviorsObject (readonly)

Returns the value of attribute behaviors.



9
10
11
# File 'lib/gem_enforcer/setup/validate.rb', line 9

def behaviors
  @behaviors
end

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



9
10
11
# File 'lib/gem_enforcer/setup/validate.rb', line 9

def gem_name
  @gem_name
end

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/gem_enforcer/setup/validate.rb', line 9

def params
  @params
end

#retrievalObject (readonly)

Returns the value of attribute retrieval.



9
10
11
# File 'lib/gem_enforcer/setup/validate.rb', line 9

def retrieval
  @retrieval
end

Instance Method Details

#current_versionObject



38
39
40
# File 'lib/gem_enforcer/setup/validate.rb', line 38

def current_version
  Gem.loaded_specs[gem_name]&.version
end

#error_statusObject



46
47
48
49
50
# File 'lib/gem_enforcer/setup/validate.rb', line 46

def error_status
  return nil if errors.empty?

  errors.map { "#{gem_name}.#{_1}" }
end

#run_validation!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gem_enforcer/setup/validate.rb', line 18

def run_validation!
  unless valid_config?
    raise Error, "Unable to run validation with invalid config."
  end
  return true if current_version.nil?

  version_list = retrieval.retrieve_version_list
  passed_behavior, failed_behavior = behaviors.partition { _1.run_behavior!(version_list:, version: current_version) }

  return true if failed_behavior.empty?


  failed_behavior.each do |failed|
    default_message = failed.version_enforcer.error_validation_message
    failed.run_failure!(message: default_message, version: current_version, version_list: version_list)
  end

  false
end

#valid_config?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gem_enforcer/setup/validate.rb', line 42

def valid_config?
  @valid_config ||= validate_config
end