Class: Gitlab::Ci::Config::Interpolation::Inputs::BaseInput

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/config/interpolation/inputs/base_input.rb

Overview

This is a common abstraction for all input types

Direct Known Subclasses

ArrayInput, BooleanInput, NumberInput, StringInput

Constant Summary collapse

ArgumentNotValidError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#errorsObject (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

#nameObject (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

#specObject (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

#valueObject (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

Returns:

  • (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_nameObject

Human readable type used in error messages

Raises:

  • (NotImplementedError)


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_hashObject



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

Returns:

  • (Boolean)


44
45
46
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 44

def valid?
  @errors.none?
end