Sha256: 38c217499bbddcb7e6a5716e436d16858fded1bc9a3b1ef5ea8aac330428fa76

Contents?: true

Size: 785 Bytes

Versions: 1

Compression:

Stored size: 785 Bytes

Contents

require 'multi_json'
require 'yaml'

require 'nugrant/bag'

module Nugrant
  module Helper
    module Bag
      def self.read(filepath, filetype, config)
        Nugrant::Bag.new(parse_data(filepath, filetype, config), config)
      end

      def self.restricted_keys()
        Nugrant::Bag.instance_methods()
      end

      private

      def self.parse_data(filepath, filetype, config)
        return if not File.exist?(filepath)

        File.open(filepath, "rb") do |file|
          return send("parse_#{filetype}", file)
        end
      rescue => error
        config.parse_error.call(filepath, error)
      end

      def self.parse_json(io)
        MultiJson.load(io.read())
      end

      def self.parse_yaml(io)
        YAML.load(io.read())
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nugrant-2.1.4 lib/nugrant/helper/bag.rb