Sha256: be7d33e23437d3c61fa1703471a976dc20046c59f8a2879826ffb22afc087c21

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 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
      verify_config_bucket_name!
      Pansophy.merge(config_bucket_name, remote_path, local_path, overwrite: true)
    end

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

    def config_remote_folder
      @config_remote_folder ||= ENV.fetch('CONFIG_REMOTE_FOLDER', 'config')
    end

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

    def version
      @version ||= ENV.fetch('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)
      return sinatra_root_pathname.join('config') if defined?(Sinatra::Application)

      fail ConfigSynchronizerError, 'Could not determine location of config folder'
    end

    private

    def self.sinatra_root_pathname
      Pathname.new(Sinatra::Application.settings.root)
    end
  end

  class ConfigSynchronizerError < StandardError
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pansophy-1.0.0 lib/pansophy/config_synchronizer.rb
pansophy-1.0.0.pre.alpha.0 lib/pansophy/config_synchronizer.rb
pansophy-0.6.0 lib/pansophy/config_synchronizer.rb
pansophy-0.5.6 lib/pansophy/config_synchronizer.rb
pansophy-0.5.5 lib/pansophy/config_synchronizer.rb
pansophy-0.5.4 lib/pansophy/config_synchronizer.rb
pansophy-0.5.3 lib/pansophy/config_synchronizer.rb
pansophy-0.5.2 lib/pansophy/config_synchronizer.rb
pansophy-0.5.1 lib/pansophy/config_synchronizer.rb
pansophy-0.5.0 lib/pansophy/config_synchronizer.rb
pansophy-0.4.0 lib/pansophy/config_synchronizer.rb
pansophy-0.3.0 lib/pansophy/config_synchronizer.rb
pansophy-0.2.6 lib/pansophy/config_synchronizer.rb
pansophy-0.2.5 lib/pansophy/config_synchronizer.rb