lib/praxis-blueprints/renderer.rb in praxis-blueprints-3.0 vs lib/praxis-blueprints/renderer.rb in praxis-blueprints-3.1

- old
+ new

@@ -1,10 +1,25 @@ module Praxis class Renderer attr_reader :include_nil attr_reader :cache + class CircularRenderingError < StandardError + attr_reader :object + attr_reader :context + + def initialize(object,context) + @object = object + @context = context + + first = Attributor.humanize_context(context[0..10]) + last = Attributor.humanize_context(context[-5..-1]) + pretty_context = "#{first}...#{last}" + super("SystemStackError in rendering #{object.class} with context: #{pretty_context}") + end + end + def initialize(include_nil: false) @cache = Hash.new do |hash,key| hash[key] = Hash.new end @@ -33,9 +48,11 @@ elsif object.kind_of? Praxis::Blueprint @cache[object.object_id][fields.object_id] ||= _render(object,fields, view, context: context) else _render(object,fields, view, context: context) end + rescue SystemStackError + raise CircularRenderingError.new(object, context) end def _render(object, fields, view=nil, context: Attributor::DEFAULT_ROOT_CONTEXT) return object if fields == true