Sha256: da34a215f56d10f7e1eb78e1688bc4c1e5e66718deb33cfd5c9bcf7582495074

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 Bytes

Contents

module Pears
  module Provider
    class Base
      attr_accessor :data

      def initialize(data, on_failure: :raise)
        @data = data
      end

      def has_key?(key)
        @data.has_key? key
      end

      def each(&block)
        @data.block(&:yield)
      end

      def [](key)
        @data[key]
      end

      private

      def parse_yaml(yaml_string)
        yaml_data = YAML.load(yaml_string)

        unless yaml_data.respond_to? :with_indifferent_access
          raise Pears::InvalidProviderData
        end

        yaml_data.with_indifferent_access
      rescue Psych::SyntaxError => e
        logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
        logger.warn "#{e.class} #{e.message}"
        raise Pears::InvalidProviderData
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pears-0.2.0 lib/pears/provider/base.rb
pears-0.1.4 lib/pears/provider/base.rb
pears-0.1.3 lib/pears/provider/base.rb