Sha256: d8cd7b80cd39e65f85d0bc109f9d3ebd0866a888177bb8a3f02e2aa30795c055

Contents?: true

Size: 744 Bytes

Versions: 3

Compression:

Stored size: 744 Bytes

Contents

require 'yaml'

module Mayl
  # Public: This module is responsible for loading YAML files and converting
  # them to Locale objects.
  #
  # Example
  #
  #   Loader.load('config/locales')
  #   # => [#<Locale:...>, #<Locale:...>]
  #
  module Loader
    # Public: Maps a set of YAML files in a directory to Locale objects, to
    # work comfortably with them.
    #
    # path - The path under which to scan for YAML files.
    #
    # Returns an Array of Locale objects.
    def self.load(path)
      locales = Dir[File.expand_path(path) << "/*.yml"].map { |filename|
        Locale.new filename, YAML.load(File.read(filename))
      }

      abort "Error: No locales found under ./#{path}" if locales.empty?

      locales
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mayl-0.2.1 lib/mayl/loader.rb
mayl-0.2.0 lib/mayl/loader.rb
mayl-0.1.0 lib/mayl/loader.rb