Class: Gitlab::Ci::Config::External::File::Base

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/external/file/base.rb

Direct Known Subclasses

Artifact, Local, Project, Remote, Template

Constant Summary collapse

YAML_WHITELIST_EXTENSION =
/.+\.(yml|yaml)$/i.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(params, context) ⇒ Base

Returns a new instance of Base.


15
16
17
18
19
20
21
# File 'lib/gitlab/ci/config/external/file/base.rb', line 15

def initialize(params, context)
  @params = params
  @context = context
  @errors = []

  validate!
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


11
12
13
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11

def context
  @context
end

#errorsObject (readonly)

Returns the value of attribute errors


11
12
13
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11

def errors
  @errors
end

#locationObject (readonly)

Returns the value of attribute location


11
12
13
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11

def location
  @location
end

#paramsObject (readonly)

Returns the value of attribute params


11
12
13
# File 'lib/gitlab/ci/config/external/file/base.rb', line 11

def params
  @params
end

Instance Method Details

#contentObject

Raises:

  • (NotImplementedError)

43
44
45
# File 'lib/gitlab/ci/config/external/file/base.rb', line 43

def content
  raise NotImplementedError, 'subclass must implement fetching raw content'
end

#error_messageObject


39
40
41
# File 'lib/gitlab/ci/config/external/file/base.rb', line 39

def error_message
  errors.first
end

#invalid_extension?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/gitlab/ci/config/external/file/base.rb', line 31

def invalid_extension?
  location.nil? || !::File.basename(location).match?(YAML_WHITELIST_EXTENSION)
end

#invalid_location_type?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/gitlab/ci/config/external/file/base.rb', line 27

def invalid_location_type?
  !location.is_a?(String)
end

#matching?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/gitlab/ci/config/external/file/base.rb', line 23

def matching?
  location.present?
end

#to_hashObject


47
48
49
# File 'lib/gitlab/ci/config/external/file/base.rb', line 47

def to_hash
  expanded_content_hash
end

#valid?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/gitlab/ci/config/external/file/base.rb', line 35

def valid?
  errors.none?
end