Sha256: a9e117d0f1fd77c118437e885e1e740089e2d85eaabdcdcbd3dad76ca333f344

Contents?: true

Size: 651 Bytes

Versions: 2

Compression:

Stored size: 651 Bytes

Contents

# frozen_string_literal: true

module Renderful
  class Renderer
    attr_reader :entry, :client

    class << self
      def resolve(field)
        define_method(field) do
          resolve(entry.send(field))
        end
      end
    end

    def initialize(entry, client:)
      @entry = entry
      @client = client
    end

    def render
      raise NotImplementedError
    end

    private

    def resolve(reference)
      if reference.is_a?(Enumerable)
        reference.map(&method(:resolve))
      elsif reference.is_a?(Contentful::Link)
        reference.resolve(client.contentful)
      else
        reference
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
renderful-0.2.0 lib/renderful/renderer.rb
renderful-0.1.0 lib/renderful/renderer.rb