Sha256: 38e7a1656975510fcce5f855e3403c61e942f8bad9aad82e206f318464b88bea

Contents?: true

Size: 1.61 KB

Versions: 24

Compression:

Stored size: 1.61 KB

Contents

require 'bundler'

module Config
  module Integrations
    class Heroku < Struct.new(:app)
      def invoke
        puts 'Setting vars...'
        heroku_command = "config:set #{vars}"
        heroku(heroku_command)
        puts 'Vars set:'
        puts heroku_command
      end

      def vars
        # Load only local options to Heroku
        Config.load_and_set_settings(
            Rails.root.join("config", "settings.local.yml").to_s,
            Rails.root.join("config", "settings", "#{environment}.local.yml").to_s,
            Rails.root.join("config", "environments", "#{environment}.local.yml").to_s
        )

        out = ''
        dotted_hash = to_dotted_hash Kernel.const_get(Config.const_name).to_hash, {}, Config.const_name
        dotted_hash.each {|key, value| out += " #{key}=#{value} "}
        out
      end

      def environment
        heroku("run 'echo $RAILS_ENV'").chomp[/(\w+)\z/]
      end

      def heroku(command)
        with_app = app ? " --app #{app}" : ""
        `heroku #{command}#{with_app}`
      end

      def `(command)
        Bundler.with_clean_env { super }
      end

      def to_dotted_hash(source, target = {}, namespace = nil)
        prefix = "#{namespace}." if namespace
        case source
          when Hash
            source.each do |key, value|
              to_dotted_hash(value, target, "#{prefix}#{key}")
            end
          when Array
            source.each_with_index do |value, index|
              to_dotted_hash(value, target, "#{prefix}#{index}")
            end
          else
            target[namespace] = source
        end
        target
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
config-5.1.0 lib/config/integrations/heroku.rb
config-5.0.0 lib/config/integrations/heroku.rb
config-4.2.1 lib/config/integrations/heroku.rb
config-4.2.0 lib/config/integrations/heroku.rb
config-4.1.0 lib/config/integrations/heroku.rb
config-4.0.0 lib/config/integrations/heroku.rb
config-3.1.1 lib/config/integrations/heroku.rb
config-3.1.0 lib/config/integrations/heroku.rb
config-3.0.0 lib/config/integrations/heroku.rb
config-2.2.3 lib/config/integrations/heroku.rb
config-2.2.2 lib/config/integrations/heroku.rb
config-2.2.1 lib/config/integrations/heroku.rb
config-2.1.0 lib/config/integrations/heroku.rb
config-2.0.0 lib/config/integrations/heroku.rb
config-1.7.2 lib/config/integrations/heroku.rb
config-1.7.1 lib/config/integrations/heroku.rb
ef-config-1.4.1 lib/config/integrations/heroku.rb
config-1.7.0 lib/config/integrations/heroku.rb
config-1.6.1 lib/config/integrations/heroku.rb
config-1.6.0 lib/config/integrations/heroku.rb