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

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.



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

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

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

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

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 14

def self.matches?(spec)
  raise NotImplementedError
end

.type_nameObject

Human readable type used in error messages

Raises:

  • (NotImplementedError)


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_hashObject



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

Returns:

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/gitlab/ci/config/interpolation/inputs/base_input.rb', line 24

def valid_value?(value)
  raise NotImplementedError
end