Sha256: 2324aa2da837b2ff08f8af23229e9ebaddc2ba0280d89639ff0b4bbeba2cd2da

Contents?: true

Size: 896 Bytes

Versions: 8

Compression:

Stored size: 896 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].bind(context)
          processed = handler.(v)
        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

8 entries across 8 versions & 1 rubygems

Version Path
auto_error-0.0.12 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.10 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.9 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.8 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.7 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.6 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.5 app/decorators/auto_error/app_error_decorator.rb
auto_error-0.0.4 app/decorators/auto_error/app_error_decorator.rb