Sha256: c29590cc6c2e8e339a40843041c78252922f9ae2c0b03a5fcf3873eb83a77f3c

Contents?: true

Size: 1.18 KB

Versions: 26

Compression:

Stored size: 1.18 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
        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

      # 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

26 entries across 26 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cloud/ci.rb
terraspace-2.2.16 lib/terraspace/cloud/ci.rb
terraspace-2.2.15 lib/terraspace/cloud/ci.rb
terraspace-2.2.14 lib/terraspace/cloud/ci.rb
terraspace-2.2.13 lib/terraspace/cloud/ci.rb
terraspace-2.2.12 lib/terraspace/cloud/ci.rb
terraspace-2.2.11 lib/terraspace/cloud/ci.rb
terraspace-2.2.10 lib/terraspace/cloud/ci.rb
terraspace-2.2.9 lib/terraspace/cloud/ci.rb
terraspace-2.2.8 lib/terraspace/cloud/ci.rb
terraspace-2.2.7 lib/terraspace/cloud/ci.rb
terraspace-2.2.6 lib/terraspace/cloud/ci.rb
terraspace-2.2.5 lib/terraspace/cloud/ci.rb
terraspace-2.2.4 lib/terraspace/cloud/ci.rb
terraspace-2.2.3 lib/terraspace/cloud/ci.rb
terraspace-2.2.2 lib/terraspace/cloud/ci.rb
terraspace-2.2.1 lib/terraspace/cloud/ci.rb
terraspace-2.2.0 lib/terraspace/cloud/ci.rb
terraspace-2.1.7 lib/terraspace/cloud/ci.rb
terraspace-2.1.6 lib/terraspace/cloud/ci.rb