Sha256: 4f3b81637fe10e79beb5644aa78197b2759d590d4195dd0dfb49c137ff7ba7fb

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'pansophy'
require 'facets/kernel/blank'

module Pansophy
  class ConfigSynchronizer
    attr_writer :config_bucket_name, :config_remote_folder, :config_local_folder, :version

    def merge
      puts "Fetching remote configuration (version #{VERSION})"
      verify_config_bucket_name!
      Pansophy.merge(config_bucket_name, remote_path, local_path, overwrite: true)
      puts 'done'
    end

    def config_bucket_name
      @config_bucket_name ||= ENV['CONFIG_BUCKET_NAME']
    end

    def config_remote_folder
      @config_remote_folder ||= (ENV['CONFIG_REMOTE_FOLDER'] || 'config')
    end

    def config_local_folder
      @config_local_folder ||= (ENV['CONFIG_LOCAL_FOLDER'] || ConfigPath.find!)
    end

    def version
      @version ||= (ENV['CONFIG_VERSION'] || '1.0')
    end

    private

    def remote_path
      Pathname.new(config_remote_folder).join(version.to_s).to_s
    end

    def local_path
      config_local_folder.to_s
    end

    def verify_config_bucket_name!
      return unless config_bucket_name.blank?
      fail ConfigSynchronizerError, 'CONFIG_BUCKET_NAME is undefined'
    end
  end

  class ConfigPath
    def self.find!
      # TODO: Extract this in a Rails specific gem
      return Rails.root.join('config') if defined?(Rails)
      fail ConfigSynchronizerError, 'Could not determine location of config folder'
    end
  end

  class ConfigSynchronizerError < StandardError
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pansophy-0.2.1 lib/pansophy/config_synchronizer.rb