Sha256: 3c9cf86b4aacfde415c9f39eec4d9db4ce629adbc9ca0f65477beb4fc18547c7

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

def copy_errors card
  card.errors.each do |att, msg|
    errors.add att, msg
  end
end

format do
  view :closed_missing, perms: :none, closed: true do
    ""
  end

  view :missing, perms: :none do
    ""
  end

  view :server_error, perms: :none do
    tr(:server_error)
  end

  view :denial, perms: :none do
    focal? ? tr(:denial) : ""
  end

  view :not_found, perms: :none do
    error_name = card.name.present? ? safe_name : tr(:not_found_no_name)
    tr(:not_found_named, cardname: error_name)
  end

  view :bad_address, perms: :none do
    root.error_status = 404
    tr(:bad_address)
  end

  view :errors do
    ["Problem:", "", standard_errors].flatten.join "\n"
  end

  def standard_errors
    card.errors.map do |attrib, msg|
      attrib == :abort ? msg : standard_error_message(attrib, msg)
    end
  end

  # for override
  def standard_error_message attribute, message
    "#{attribute.to_s.upcase}: #{message}"
  end

  def unsupported_view_error_message view
    tr(:unsupported_view, view: view, cardname: card.name)
  end
end

format :json do
  view :errors do
    format_error error_list
  end

  view :server_error, :errors
  view :denial, :errors
  view :not_found, :errors

  view :bad_address do
    format_error super()
  end

  def format_error error
    { error_status: error_status,
      errors: error }
  end

  def error_list
    card.errors.each_with_object([]) do |(field, message), list|
      list << { field: field, message: message }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
card-1.97.0.1 mod/standard/set/all/error.rb
card-1.97.0 mod/standard/set/all/error.rb
card-1.96.8 mod/standard/set/all/error.rb
card-1.96.7 mod/standard/set/all/error.rb
card-1.96.6 mod/standard/set/all/error.rb
card-1.96.5 mod/standard/set/all/error.rb
card-1.96.4 mod/standard/set/all/error.rb
card-1.96.3 mod/standard/set/all/error.rb