Class: Terraspace::Cloud::Ci

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace/cloud/ci.rb

Class Method Summary collapse

Class Method Details

.detectObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/terraspace/cloud/ci.rb', line 20

def detect
  detected = meta.find do |data|
    env_key = data[:env_key] # IE: ENV['GITHUB_ACTIONS']
    env_value = data[:env_value] # IE: "string" or /pattern/
    if env_value
      v = ENV[env_key]
      v && match?(v, env_value)
    else
      ENV[env_key] # only env_key
    end
  end
  interface_class(detected) if detected
end

.interface_class(meta) ⇒ Object

IE: TerraspaceCiGithub::Interface



35
36
37
# File 'lib/terraspace/cloud/ci.rb', line 35

def interface_class(meta)
  "terraspace_ci_#{meta[:name]}::Interface".classify.constantize
end

.match?(v, env_value) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/terraspace/cloud/ci.rb', line 39

def match?(v, env_value)
  case v
  when String
    v == env_value
  when Regexp
    v.match(env_value)
  end
end

.register(data) ⇒ Object



14
15
16
17
18
# File 'lib/terraspace/cloud/ci.rb', line 14

def register(data)
  self.meta << data unless meta.find do |m|
    m[:name] == data[:name]
  end
end