Class: Gitlab::Ci::Config::Interpolation::Inputs::BaseInput
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::Interpolation::Inputs::BaseInput
- Defined in:
- lib/gitlab/ci/config/interpolation/inputs/base_input.rb
Overview
This is a common abstraction for all input types
Direct Known Subclasses
Constant Summary collapse
- ArgumentNotValidError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.matches?(spec) ⇒ Boolean
Checks whether the class matches the type in the specification.
-
.type_name ⇒ Object
Human readable type used in error messages.
Instance Method Summary collapse
-
#initialize(name:, spec:, value:) ⇒ BaseInput
constructor
A new instance of BaseInput.
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
-
#valid_value?(value) ⇒ Boolean
Checks whether the provided value is of the given type.
Constructor Details
#initialize(name:, spec:, value:) ⇒ BaseInput
Returns a new instance of BaseInput.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 30 def initialize(name:, spec:, value:) @name = name @errors = [] # Treat minimal spec definition (nil) as a valid hash: # spec: # inputs: # website: @spec = spec || {} # specification from input definition @value = value # actual value provided by the user validate! end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
28 29 30 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 28 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 28 def name @name end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
28 29 30 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 28 def spec @spec end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
28 29 30 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 28 def value @value end |
Class Method Details
.matches?(spec) ⇒ Boolean
Checks whether the class matches the type in the specification
14 15 16 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 14 def self.matches?(spec) raise NotImplementedError end |
.type_name ⇒ Object
Human readable type used in error messages
19 20 21 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 19 def self.type_name raise NotImplementedError end |
Instance Method Details
#to_hash ⇒ Object
44 45 46 47 48 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 44 def to_hash raise ArgumentNotValidError unless valid? { name => actual_value } end |
#valid? ⇒ Boolean
50 51 52 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 50 def valid? @errors.none? end |
#valid_value?(value) ⇒ Boolean
Checks whether the provided value is of the given type
24 25 26 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 24 def valid_value?(value) raise NotImplementedError end |