Sha256: c49f6f9908858c1ef191e39a6b761743d7786c198f2d4e63bc85eaca8974d234

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

module EnvBranch
  class Base
    attr_reader :branch_name

    def initialize(&block)
      @branch_name =
        if block_given?
          block.call || fetch_branch_name
        else
          fetch_branch_name
        end
    end

    # travis-ci.org:
    #   ENV['TRAVIS_BRANCH']
    # circleci.com:
    #   ENV['CIRCLE_BRANCH']
    #
    # @see http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
    #   Environment Variables - Travis CI
    # @see https://circleci.com/docs/environment-variables#build-details
    #   Environment variables - CircleCI
    def fetch_branch_name
      if ENV['TRAVIS_BRANCH'] && !ENV['TRAVIS_BRANCH'].empty?
        ENV['TRAVIS_BRANCH']
      elsif ENV['CIRCLE_BRANCH'] && !ENV['CIRCLE_BRANCH'].empty?
        ENV['CIRCLE_BRANCH']
      end
    end

    def branch?
      !branch_name.nil?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
env_branch-0.2.0 lib/env_branch/base.rb