Class: Gitlab::Config::Entry::Simplifiable

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

Defined Under Namespace

Classes: EntryStrategy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, **metadata, &blk) ⇒ Simplifiable

Returns a new instance of Simplifiable.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/config/entry/simplifiable.rb', line 11

def initialize(config, **, &blk)
  unless self.class.const_defined?(:UnknownStrategy)
    raise ArgumentError, 'UndefinedStrategy not available!'
  end

  strategy = self.class.strategies.find do |variant|
    variant.condition.call(config)
  end

  entry = self.class.entry_class(strategy)

  @subject = entry.new(config, , &blk)

  super(@subject)
end

Instance Attribute Details

#subjectObject (readonly)

Returns the value of attribute subject


9
10
11
# File 'lib/gitlab/config/entry/simplifiable.rb', line 9

def subject
  @subject
end

Class Method Details

.defaultObject


45
46
# File 'lib/gitlab/config/entry/simplifiable.rb', line 45

def self.default
end

.entry_class(strategy) ⇒ Object


37
38
39
40
41
42
43
# File 'lib/gitlab/config/entry/simplifiable.rb', line 37

def self.entry_class(strategy)
  if strategy.present?
    strategy.klass || self.const_get(strategy.name, false)
  else
    self::UnknownStrategy
  end
end

.strategiesObject


33
34
35
# File 'lib/gitlab/config/entry/simplifiable.rb', line 33

def self.strategies
  @strategies ||= []
end

.strategy(name, **opts) ⇒ Object


27
28
29
30
31
# File 'lib/gitlab/config/entry/simplifiable.rb', line 27

def self.strategy(name, **opts)
  EntryStrategy.new(name, opts.dig(:class), opts.fetch(:if)).tap do |strategy|
    strategies.append(strategy)
  end
end