Sha256: 11a1048ee000cc89b1ba2bfe6eb66fb567550775ec63eaba2dca0babc7f6482a

Contents?: true

Size: 1.2 KB

Versions: 60

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Buildkite
  class Env
    BUILDKITE = 'BUILDKITE'
    PREFIX = "#{BUILDKITE}_"

    module Fallback
      def method_missing(method_name, *_args, &_block) # rubocop:disable Style/MethodMissingSuper
        env_name = "#{PREFIX}#{method_name.to_s.gsub(/\?\z/, '').upcase}"

        if method_name.to_s.end_with?('?')
          @env.key?(env_name)
        elsif @env.key?(env_name)
          @env.fetch(env_name)
        else
          raise NoMethodError, "undefined method #{method_name} for #{self} because ENV[\"#{env_name}\"] is not defined"
        end
      end

      def respond_to_missing?(method_name, include_private = false)
        method_name.to_s.end_with?('?') || @env.key?("#{PREFIX}#{method_name.upcase}") || super
      end
    end
    include Fallback

    def self.load(env)
      new(env) if env[BUILDKITE]
    end

    def initialize(env)
      @env = env
    end

    def default_branch?
      pipeline_default_branch == branch
    end

    def pull_request
      super == 'false' ? false : Integer(super)
    end

    # Integer methods
    %w(
      build_number
    ).each do |meth|
      define_method(meth) do
        Integer(super())
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
buildkite-builder-2.3.0 lib/buildkite/env.rb
buildkite-builder-2.2.0 lib/buildkite/env.rb
buildkite-builder-2.1.0 lib/buildkite/env.rb
buildkite-builder-2.0.0 lib/buildkite/env.rb
buildkite-builder-2.0.0.beta4 lib/buildkite/env.rb
buildkite-builder-2.0.0.beta3 lib/buildkite/env.rb
buildkite-builder-2.0.0.beta2 lib/buildkite/env.rb
buildkite-builder-2.0.0.beta1 lib/buildkite/env.rb
buildkite-builder-1.4.1 lib/buildkite/env.rb
buildkite-builder-1.4.0 lib/buildkite/env.rb
buildkite-builder-1.3.1 lib/buildkite/env.rb
buildkite-builder-1.3.0 lib/buildkite/env.rb
buildkite-builder-1.2.0 lib/buildkite/env.rb
buildkite-builder-1.1.0 lib/buildkite/env.rb
buildkite-builder-1.0.0 lib/buildkite/env.rb
buildkite-builder-1.0.0.beta.5 lib/buildkite/env.rb
buildkite-builder-1.0.0.beta.4 lib/buildkite/env.rb
buildkite-builder-1.0.0.beta.3 lib/buildkite/env.rb
buildkite-builder-1.0.0.beta.2 lib/buildkite/env.rb
buildkite-builder-1.0.0.beta.1 lib/buildkite/env.rb