Sha256: 2b05ef5cfcef192abcc4eade322e1df6fbbf518183e1363714a187ee63f7196f

Contents?: true

Size: 971 Bytes

Versions: 36

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

module LinkedRails
  class RDFError
    include ActiveModel::Model

    attr_accessor :error, :iri, :message, :status

    def initialize(status, requested_url, original_error)
      self.status = status
      self.error = original_error.is_a?(StandardError) ? original_error : original_error.new
      self.message = error.message unless Rails.env.production?
      self.iri = ::RDF::URI(requested_url)
    end

    def graph # rubocop:disable Metrics/AbcSize
      g = ::RDF::Graph.new
      g << [iri, Vocab.schema.name, title] if title
      g << [iri, Vocab.schema.text, message]
      g << [iri, Vocab.rdfv.type, rdf_type]
      g
    end

    def title
      @title ||= I18n.t('linked_rails.status')[status] || I18n.t('linked_rails.status')[500]
    end

    def rdf_type
      @rdf_type ||= Vocab.ontola["errors/#{error.class.name.demodulize}Error"]
    end

    def self.serializer_class
      RDFErrorSerializer
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g4c8e21c9f lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g76dedd8ba lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g7123943aa lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g72bb595fe lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gd8464437f lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g661cde413 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.ge09501794 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gc3dfc6914 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g92825d924 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g14b377f91 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g2c53724b3 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g83aa52ab3 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gaa82a222d lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g9b7bc9073 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.ge1306665a lib/linked_rails/rdf_error.rb
linked_rails-0.0.4 lib/linked_rails/rdf_error.rb