Sha256: 9f479e298c53eff50ef1dc09bb42daa9a6cbdef77d243c4202dc9b21afd62094

Contents?: true

Size: 745 Bytes

Versions: 2

Compression:

Stored size: 745 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_data)
        yaml_data = YAML.load(yaml_data)
        raise Pears::InvalidProviderData if yaml_data.is_a? String
        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

2 entries across 2 versions & 1 rubygems

Version Path
pears-0.1.1 lib/pears/provider/base.rb
pears-0.1.0 lib/pears/provider/base.rb