Sha256: fd559c023b3d733f42b8c8c487258af12dbb2d771fc928c73bc3580262f6b2c6

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module Instapusher
  class CommandBuilder

    attr_reader :base

    delegate :setttings,        to: :base
    delegate :heroku_app_name,  to: :base
    delegate :callbacks,        to: :base
    delegate :job,              to: :base

    def initialize base
      raise 'boom'

      @base = base
      @commands = []
    end

    def build
      add_pre_config_commands
      add_config_environment_commands
      add_before_every_install_commands
      add_callback_commands
      add_after_every_install

      commands.flatten!.compact!
      feedback_to_user
      commands
    end

    private

    def feedback_to_user
      job.add_log 'Following commands will be executed:'
      commands.each do |cmd|
        job.add_log(' '*4 + cmd)
      end
    end

    def add_after_every_install
      commands << settings.post_config_commands.after_every_install
    end

    def add_callback_commands
      callbacks.each do |callback|
        commands << settings.post_config_commands[callback]
      end
    end

    def add_before_every_install_commands
      commands << settings.post_config_commands.before_every_install
    end

    def add_pre_config_commands
      commands << settings.pre_config_commands
    end

    def add_config_environment_commands
      return unless settings.config
      config_cmd = settings.config.map { |key, value| "#{key.upcase}=#{value}" }
     commands << "bundle exec heroku config:add #{config_cmd.join(' ')} --app #{heroku_app_name}"
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
instapusher-0.0.26 lib/instapusher/command_builder.rb
instapusher-0.0.25 lib/instapusher/command_builder.rb
instapusher-0.0.24 lib/instapusher/command_builder.rb
instapusher-0.0.23 lib/instapusher/command_builder.rb
instapusher-0.0.22 lib/instapusher/command_builder.rb