Class: GemEnforcer::Setup::Validate
- Inherits:
-
Object
- Object
- GemEnforcer::Setup::Validate
- Defined in:
- lib/gem_enforcer/setup/validate.rb
Instance Attribute Summary collapse
-
#behaviors ⇒ Object
readonly
Returns the value of attribute behaviors.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#retrieval ⇒ Object
readonly
Returns the value of attribute retrieval.
Instance Method Summary collapse
- #current_version ⇒ Object
- #error_status ⇒ Object
-
#initialize(name:, **params) ⇒ Validate
constructor
A new instance of Validate.
- #run_validation! ⇒ Object
- #valid_config? ⇒ Boolean
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
#behaviors ⇒ Object (readonly)
Returns the value of attribute behaviors.
9 10 11 |
# File 'lib/gem_enforcer/setup/validate.rb', line 9 def behaviors @behaviors end |
#gem_name ⇒ Object (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 |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/gem_enforcer/setup/validate.rb', line 9 def params @params end |
#retrieval ⇒ Object (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_version ⇒ Object
38 39 40 |
# File 'lib/gem_enforcer/setup/validate.rb', line 38 def current_version Gem.loaded_specs[gem_name]&.version end |
#error_status ⇒ Object
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| = failed.version_enforcer. failed.run_failure!(message: , version: current_version, version_list: version_list) end false end |
#valid_config? ⇒ Boolean
42 43 44 |
# File 'lib/gem_enforcer/setup/validate.rb', line 42 def valid_config? @valid_config ||= validate_config end |