Sha256: d8038d946681c3d32b8c854cc05cfaf2d3a8b5e64e919aa7e74e803d311a0965

Contents?: true

Size: 650 Bytes

Versions: 1

Compression:

Stored size: 650 Bytes

Contents

require 'active_support/inflector'
require 'json'

module SettingsJs
  class Merger

    def to_hash
      unless config.keys.respond_to?(:reduce)
        raise TypeError.new('the configuration key "keys" must be reduceable')
      end

      config.keys.reduce({}) { |hash, base_key| hash.merge(adapter.to_hash(base_key)) }
    end

    def to_json
      to_hash.to_json
    end

  private

    def config
      SettingsJs::Config.instance
    end

    def adapter
      adapter_proxy_path = "settings_js/adapters/#{config.adapter}"

      require adapter_proxy_path
      adapter_proxy_path.classify.constantize.new(config.klass)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
settings_js-0.0.1 lib/settings_js/merger.rb