Sha256: 6bea5345b838c6d5cda8bdfa2c3aed9084f1985f1601262234624cf04e08be3c

Contents?: true

Size: 1.42 KB

Versions: 47

Compression:

Stored size: 1.42 KB

Contents

require 'engineyard/error'

module EY
  class DeployConfig
    class Ref

      def initialize(cli_opts, env_config, repo, ui)
        @cli_opts  = cli_opts
        @default   = env_config.branch
        @repo      = repo
        @force_ref = @cli_opts.fetch('force_ref', false)
        @ui        = ui

        if @force_ref.kind_of?(String)
          @ref, @force_ref = @force_ref, true
        else
          @ref = @cli_opts.fetch('ref', nil)
          @ref = nil if @ref == ''
        end
      end

      def when_inside_repo
        if !@force_ref && @ref && @default && @ref != @default
          raise BranchMismatchError.new(@default, @ref)
        elsif @force_ref && @ref && @default
          @ui.say "Default ref overridden with #{@ref.inspect}."
        end

        @ref || use_default || use_current_branch || raise(RefRequired.new(@cli_opts))
      end

      def use_default
        if @default
          @ui.say "Using default branch #{@default.inspect} from ey.yml."
          @default
        end
      end

      def use_current_branch
        if current = @repo.current_branch
          @ui.say "Using current HEAD branch #{current.inspect}."
          current
        end
      end

      # a.k.a. not in the correct repo
      #
      # returns the ref if it was passed in the cli opts.
      # or raise
      def when_outside_repo
        @ref or raise RefAndMigrateRequiredOutsideRepo.new(@cli_opts)
      end

    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
crazy-yard-3.2.2 lib/engineyard/deploy_config/ref.rb
engineyard-3.2.5 lib/engineyard/deploy_config/ref.rb
engineyard-3.2.4 lib/engineyard/deploy_config/ref.rb
engineyard-3.2.3 lib/engineyard/deploy_config/ref.rb
engineyard-4.0.0.pre3 lib/engineyard/deploy_config/ref.rb
engineyard-4.0.0.pre2 lib/engineyard/deploy_config/ref.rb
engineyard-4.0.0.pre1 lib/engineyard/deploy_config/ref.rb
engineyard-3.2.1 lib/engineyard/deploy_config/ref.rb
engineyard-3.2.0 lib/engineyard/deploy_config/ref.rb
engineyard-3.1.3 lib/engineyard/deploy_config/ref.rb
engineyard-3.1.2 lib/engineyard/deploy_config/ref.rb
engineyard-3.1.1 lib/engineyard/deploy_config/ref.rb
engineyard-3.1.0 lib/engineyard/deploy_config/ref.rb
engineyard-3.0.1 lib/engineyard/deploy_config/ref.rb
engineyard-3.0.0 lib/engineyard/deploy_config/ref.rb
engineyard-2.3.3 lib/engineyard/deploy_config/ref.rb
engineyard-2.3.2 lib/engineyard/deploy_config/ref.rb
engineyard-2.3.1 lib/engineyard/deploy_config/ref.rb
engineyard-2.3.0 lib/engineyard/deploy_config/ref.rb
engineyard-2.2.1 lib/engineyard/deploy_config/ref.rb