File: configuration.rb

package info (click to toggle)
ruby-countries 4.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,196 kB
  • sloc: ruby: 2,085; makefile: 4
file content (57 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module ISO3166
  class << self
    attr_writer :configuration
  end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.reset
    @configuration = Configuration.new
    Data.reset
  end

  def self.configure
    yield(configuration)
  end

  class Configuration
    attr_accessor :locales, :loaded_locales

    def initialize
      @locales = default_locales
      @loaded_locales = []
    end

    # Enables the integration with the {Money}[https://github.com/RubyMoney/money] gem
    #
    # Please note that it requires you to add "money" gem to your gemfile.
    #
    #   gem "money", "~> 6.9"
    #
    # *WARNING* if you have a top level class named +Money+ you will conflict with this gem.
    #
    # @example
    #   c = ISO3166::Country['us']
    #   c.currency.iso_code # => 'USD'
    #   c.currency.name # => 'United States Dollar'
    #   c.currency.symbol # => '$'
    def enable_currency_extension!
      require 'countries/country/currency_methods'
      ISO3166::Country.prepend(ISO3166::CountryCurrencyMethods)
    end

    private

    def default_locales
      locales = if Object.const_defined?('I18n') && I18n.respond_to?(:available_locales)
                  I18n.available_locales
                else
                  [:en]
                end

      locales.empty? ? [:en] : locales
    end
  end
end