Sha256: f67f0e90ee768f2ebdaae821b09affbbba9c7ad1e23f737cc24eef59b6ec3b4f
Contents?: true
Size: 1.61 KB
Versions: 24
Compression:
Stored size: 1.61 KB
Contents
require 'active_support/core_ext/module/delegation' module JSONAPIonify module Api class ErrorsObject delegate :present?, to: :collection class Evaluator Structure::Objects::Error.permitted_keys.each do |key| define_method(key) do |value| @error[key] = value end end def initialize(error) @error = error freeze end def meta JSONAPIonify::Structure::Helpers::MetaDelegate.new @error end def pointer(value) @error[:source] ||= {} @error[:source][:pointer] = value end def parameter(value) @error[:source] ||= {} @error[:source][:parameter] = value end end def evaluate(*args, error_block:, runtime_block: nil, backtrace: nil) backtrace ||= caller runtime_block ||= proc {} error = Structure::Objects::Error.new evaluator = Evaluator.new(error) collection << error [runtime_block, error_block].each do |block| evaluator.instance_exec(*args, &block) if block end if JSONAPIonify.show_backtrace == true error[:meta] ||= {} error[:meta][:backtrace] = backtrace end end def top_level JSONAPIonify.new_object.tap do |obj| obj[:errors] = collection end end def collection @collection ||= Structure::Collections::Errors.new end def set(collection) @collection = collection end end end end
Version data entries
24 entries across 24 versions & 1 rubygems