Class: Gitlab::Config::Entry::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/config/entry/factory.rb

Overview

Factory class responsible for fabricating entry objects.

Constant Summary collapse

InvalidFactory =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_class) ⇒ Factory

Returns a new instance of Factory.


14
15
16
17
18
# File 'lib/gitlab/config/entry/factory.rb', line 14

def initialize(entry_class)
  @entry_class = entry_class
  @metadata = {}
  @attributes = { default: entry_class.default }
end

Instance Attribute Details

#entry_classObject (readonly)

Returns the value of attribute entry_class


12
13
14
# File 'lib/gitlab/config/entry/factory.rb', line 12

def entry_class
  @entry_class
end

Instance Method Details

#create!Object

Raises:


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gitlab/config/entry/factory.rb', line 51

def create!
  raise InvalidFactory unless defined?(@value)

  ##
  # We assume that unspecified entry is undefined.
  # See issue #18775.
  #
  if @value.nil?
    Entry::Unspecified.new(fabricate_unspecified)
  else
    fabricate(entry_class, @value)
  end
end

#descriptionObject


35
36
37
# File 'lib/gitlab/config/entry/factory.rb', line 35

def description
  @attributes[:description]
end

#inheritObject


39
40
41
# File 'lib/gitlab/config/entry/factory.rb', line 39

def inherit
  @attributes[:inherit]
end

#inheritable?Boolean

Returns:


43
44
45
# File 'lib/gitlab/config/entry/factory.rb', line 43

def inheritable?
  @attributes[:inherit]
end

#metadata(metadata) ⇒ Object


25
26
27
28
# File 'lib/gitlab/config/entry/factory.rb', line 25

def ()
  @metadata.merge!(.compact)
  self
end

#reserved?Boolean

Returns:


47
48
49
# File 'lib/gitlab/config/entry/factory.rb', line 47

def reserved?
  @attributes[:reserved]
end

#value(value) ⇒ Object


20
21
22
23
# File 'lib/gitlab/config/entry/factory.rb', line 20

def value(value)
  @value = value
  self
end

#with(attributes) ⇒ Object


30
31
32
33
# File 'lib/gitlab/config/entry/factory.rb', line 30

def with(attributes)
  @attributes.merge!(attributes.compact)
  self
end