Sha256: 9f7746fe900d7f1570e9e67a185300217b9e33fca370c1a3c2faa8d6fb3b9919
Contents?: true
Size: 1.3 KB
Versions: 4
Compression:
Stored size: 1.3 KB
Contents
module Terraspace::Cloud class Ci # Example meta: # # [ # {name: "github", interface_class: TerrapaceCiGithub::Interface}, # {name: "gitlab", interface_class: TerrapaceCiGitlab::Interface}, # ] # class_attribute :meta # not shared with child classes self.meta = [] class << self def register(data) self.meta << data unless meta.find do |m| m[:name] == data[:name] end end def detect return Generic if ENV['TS_CI_REPO'] 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 klass = if detected interface_class(detected) else Manual end klass.new end # IE: TerraspaceCiGithub::Interface def interface_class(meta) "terraspace_ci_#{meta[:name]}::Interface".classify.constantize end def match?(v, env_value) case v when String v == env_value when Regexp v.match(env_value) end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
terraspace-2.0.3 | lib/terraspace/cloud/ci.rb |
terraspace-2.0.2 | lib/terraspace/cloud/ci.rb |
terraspace-2.0.1 | lib/terraspace/cloud/ci.rb |
terraspace-2.0.0 | lib/terraspace/cloud/ci.rb |