Sha256: 4527cbb21890f455668c765ca8ce14dbf5a6644d2621ffdba126edcd6a944f5d

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true
require 'yaml'

class Money
  class Currency
    module Loader
      class << self
        def load_currencies
          currency_data_path = File.expand_path("../../../../config", __FILE__)

          currencies = {}
          currencies.merge! YAML.load_file("#{currency_data_path}/currency_historic.yml")
          currencies.merge! YAML.load_file("#{currency_data_path}/currency_non_iso.yml")
          currencies.merge! YAML.load_file("#{currency_data_path}/currency_iso.yml")
          deep_deduplicate!(currencies)
        end

        private

        def deep_deduplicate!(data)
          case data
          when Hash
            return data if data.frozen?
            data.transform_keys! { |k| deep_deduplicate!(k) }
            data.transform_values! { |v| deep_deduplicate!(v) }
            data.freeze
          when Array
            return data if data.frozen?
            data.map! { |d| deep_deduplicate!(d) }.freeze
          when String
            -data
          else
            data.duplicable? ? data.freeze : data
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shopify-money-0.14.3 lib/money/currency/loader.rb