Module: Exekutor::Internal::ConfigurationBuilder
- Extended by:
- ActiveSupport::Concern
- Included in:
- Configuration
- Defined in:
- lib/exekutor/internal/configuration_builder.rb
Overview
DSL for the configuration
Instance Method Summary collapse
-
#set(**options) ⇒ self
Sets option values in bulk.
-
#validate_option_enum!(name, value, *allowed_values) ⇒ Object
Validates whether the value is a valid enum option.
-
#validate_option_presence!(name, value) ⇒ Object
Validates whether the option is present for configuration values that are required raise [StandardError] if the value is nil or blank.
-
#validate_option_range!(name, value, allowed_range) ⇒ Object
Validates whether the value falls in the allowed range.
-
#validate_option_type!(name, value, *allowed_types) ⇒ Object
Validates whether the value class is allowed.
Instance Method Details
#set(**options) ⇒ self
Sets option values in bulk
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/exekutor/internal/configuration_builder.rb', line 21 def set(**) = .keys - __option_names if .present? raise error_class, "Invalid option#{"s" if .many?}: #{ .map(&:inspect).join(", ")}" end .each do |name, value| send :"#{name}=", value end self end |
#validate_option_enum!(name, value, *allowed_values) ⇒ Object
Validates whether the value is a valid enum option
103 104 105 106 107 108 109 110 |
# File 'lib/exekutor/internal/configuration_builder.rb', line 103 def validate_option_enum!(name, value, *allowed_values) return if allowed_values.include?(value) raise error_class, "##{name} should be one of #{ allowed_values.map(&:inspect) .to_sentence(two_words_connector: " or ", last_word_connector: ", or ") }" end |
#validate_option_presence!(name, value) ⇒ Object
Validates whether the option is present for configuration values that are required raise [StandardError] if the value is nil or blank
84 85 86 87 88 |
# File 'lib/exekutor/internal/configuration_builder.rb', line 84 def validate_option_presence!(name, value) return if value.present? || value.is_a?(FalseClass) raise error_class, "##{name} cannot be #{value.nil? ? "nil" : "blank"}" end |
#validate_option_range!(name, value, allowed_range) ⇒ Object
Validates whether the value falls in the allowed range
114 115 116 117 118 119 120 121 |
# File 'lib/exekutor/internal/configuration_builder.rb', line 114 def validate_option_range!(name, value, allowed_range) return if allowed_range.include?(value) raise error_class, <<~MSG ##{name} should be between #{allowed_range.first.inspect} and #{allowed_range.last.inspect}#{ " (exclusive)" if allowed_range.respond_to?(:exclude_end?) && allowed_range.exclude_end?} MSG end |
#validate_option_type!(name, value, *allowed_types) ⇒ Object
Validates whether the value class is allowed
92 93 94 95 96 97 98 99 |
# File 'lib/exekutor/internal/configuration_builder.rb', line 92 def validate_option_type!(name, value, *allowed_types) return if allowed_types.include?(value.class) raise error_class, "##{name} should be an instance of #{ allowed_types.map { |c| c == NilClass || c.nil? ? "nil" : c } .to_sentence(two_words_connector: " or ", last_word_connector: ", or ") } (Actual: #{value.class})" end |