Class: Ci::Inputs::StringInput

Inherits:
BaseInput show all
Extended by:
Gitlab::Utils::Override
Defined in:
lib/ci/inputs/string_input.rb

Instance Attribute Summary

Attributes inherited from BaseInput

#errors, #name, #spec

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods inherited from BaseInput

#actual_value, #default, #default_value_present?, #description, #initialize, #options, #regex, #required?, #rules, #type, #validate_param!

Constructor Details

This class inherits a constructor from Ci::Inputs::BaseInput

Class Method Details

.matches?(spec) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ci/inputs/string_input.rb', line 8

def self.matches?(spec)
  # The input spec can be `nil` when using a minimal specification
  # and also when `type` is not specified.
  #
  # ```yaml
  # spec:
  #   inputs:
  #     foo:
  # ```
  spec.nil? || super || (spec.is_a?(Hash) && !spec.key?(:type))
end

.type_nameObject



20
21
22
# File 'lib/ci/inputs/string_input.rb', line 20

def self.type_name
  'string'
end

Instance Method Details

#validate_options(value, all_params = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/ci/inputs/string_input.rb', line 31

def validate_options(value, all_params = {})
  allowed_options = rules ? resolved_options(all_params) : options
  return unless allowed_options && value
  return if allowed_options.map(&:to_s).include?(value)

  error("`#{value}` cannot be used because it is not in the list of allowed options")
end

#validate_type(value, _default) ⇒ Object



25
26
27
28
# File 'lib/ci/inputs/string_input.rb', line 25

def validate_type(value, _default)
  # Since coerced_value always converts to string via value.to_s,
  # this validation will always pass for StringInput
end