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
-
.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
Constructor Details
#initialize(name:, spec:, value:) ⇒ BaseInput
Returns a new instance of BaseInput.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 24 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.
22 23 24 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 22 def errors @errors end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 22 def name @name end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
22 23 24 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 22 def spec @spec end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
22 23 24 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 22 def value @value end |
Class Method Details
.matches?(spec) ⇒ Boolean
13 14 15 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 13 def self.matches?(spec) spec.is_a?(Hash) && spec[:type] == type_name end |
.type_name ⇒ Object
Human readable type used in error messages
18 19 20 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 18 def self.type_name raise NotImplementedError end |
Instance Method Details
#to_hash ⇒ Object
38 39 40 41 42 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 38 def to_hash raise ArgumentNotValidError unless valid? { name => actual_value } end |
#valid? ⇒ Boolean
44 45 46 |
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 44 def valid? @errors.none? end |