Sha256: f4e17b815d0f390b659a9fb2806ddce1ed402f347aceaab93ea877a92b6c182c

Contents?: true

Size: 1008 Bytes

Versions: 7

Compression:

Stored size: 1008 Bytes

Contents

require "pathname"
require "json"
require "yaml"

module Ginny

  # Load data from a YAML file.
  #
  # @param path [String]
  # @return [Hash<Symbol>]
  def self.load_yaml(path)
    return Coolkit.symbolize_keys(YAML.load_file(File.expand_path(path)))
  end

  # Load data from a JSON file.
  #
  # @param path [String]
  # @return [Hash<Symbol>]
  def self.load_json(path)
    return JSON.parse(File.read(File.expand_path(path)), symbolize_names: true)
  end

  # @param path [String] Path of the file to determine the extension of.
  # @return [String]
  def self.get_extension(path)
    file = Pathname.new(path)
    return file.extname.downcase
  end

  # Load data from a YAML or JSON file.
  #
  # @param path [String]
  # @return [Hash<Symbol>]
  def self.load_file(path)
    case Pathname.new(path).extname.downcase
    when ".yml", ".yaml"
      return self.load_yaml(path)
    when ".json"
      return self.load_json(path)
    else
      raise Ginny::Error "invalid file type"
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ginny-0.6.3 lib/ginny/load.rb
ginny-0.6.2 lib/ginny/load.rb
ginny-0.6.1 lib/ginny/load.rb
ginny-0.6.0 lib/ginny/load.rb
ginny-0.5.4 lib/ginny/load.rb
ginny-0.5.3 lib/ginny/load.rb
ginny-0.5.2 lib/ginny/load.rb