Sha256: 6aafda0fd9500e21847c2f84ea0072d15f70e161f1ce2392a1bb7c6967243713

Contents?: true

Size: 995 Bytes

Versions: 1

Compression:

Stored size: 995 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

      def purge
        true
      end

      private

      def parse_yaml(yaml_string)
        yaml_data = YAML.load(
            yaml_string,
            permitted_classes: [ActiveSupport::HashWithIndifferentAccess,
              Hash,
              Symbol
            ]
          )

        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

1 entries across 1 versions & 1 rubygems

Version Path
pears-0.3.5 lib/pears/provider/base.rb