Sha256: 0bb238e7d938d8420cc0622b837f1962a79a2836544eed8c8b661e9cb749e584

Contents?: true

Size: 910 Bytes

Versions: 5

Compression:

Stored size: 910 Bytes

Contents

module AutoError
  class AppErrorDecorator < Draper::Decorator
    def as_json( context )
      r = source.attributes
      (r['data']||{}).entries.each do |k, v|
        next if v.nil?
        k = k.to_sym
        if k != :params || AutoError::Config.data_handlers.has_key?(k)
          handler = AutoError::Config.data_handlers[k]
          processed = context.instance_exec( *[v], &handler )
        elsif k == :params
          processed = handle_params(v)
        end
        r['data'][k.to_s] = processed.html_safe
      end
      r
    end

    private

    def handle_params( h )
      %{
        <a href='javascript:void(0);' onclick='$(this).siblings(".params").reveal();'>show params...</a>
        <div class='params reveal-modal'>
          <a class="close-reveal-modal">&#215;</a>
          <h4>Params</h4>
          <pre>#{JSON.pretty_generate(h)}</pre>
        </div>
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
auto_error-0.0.18 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.16 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.15 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.14 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.13 app/decorators/auto_error/app_error_decorator.rb