Class: GemEnforcer::Setup::Helper::OnFailure
- Inherits:
-
Object
- Object
- GemEnforcer::Setup::Helper::OnFailure
- Defined in:
- lib/gem_enforcer/setup/helper/on_failure.rb
Constant Summary collapse
- ALLOWED_KEYS =
[LOG_LEVEL = :log_level, FAILURE_BEHAVIOR = :behavior, MESSAGE = :message]
- ALLOWED_FAILURE_BEHAVIOR =
[:raise, :exit, DEFAULT_BEHAVIOR = :none]
- DEFAULT_LOG_LEVEL =
:error
Instance Attribute Summary collapse
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#on_failure ⇒ Object
readonly
Returns the value of attribute on_failure.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(gem_name:, on_failure:) ⇒ OnFailure
constructor
A new instance of OnFailure.
- #run_on_failure!(message:, **params) ⇒ Object
- #valid_config? ⇒ Boolean
Constructor Details
#initialize(gem_name:, on_failure:) ⇒ OnFailure
Returns a new instance of OnFailure.
13 14 15 16 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 13 def initialize(gem_name:, on_failure:) @gem_name = gem_name @on_failure = on_failure.transform_keys(&:to_sym) rescue on_failure end |
Instance Attribute Details
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
7 8 9 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 7 def gem_name @gem_name end |
#on_failure ⇒ Object (readonly)
Returns the value of attribute on_failure.
7 8 9 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 7 def on_failure @on_failure end |
Instance Method Details
#errors ⇒ Object
22 23 24 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 22 def errors @errors ||= [] end |
#run_on_failure!(message:, **params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 26 def run_on_failure!(message:, **params) unless valid_config? raise ConfigError, "Attempted to run on_failure with an invalid config." end = ( || ) % params GemEnforcer.logger.public_send(on_failure_log_level, ) case on_failure_behavior.to_sym when :raise raise ValidationError, when :exit Kernel.exit(1) end true end |
#valid_config? ⇒ Boolean
18 19 20 |
# File 'lib/gem_enforcer/setup/helper/on_failure.rb', line 18 def valid_config? @valid_config ||= validate_config end |