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.g3aeec2263 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gacd5f04d4 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gb0b6aea40 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g792a1b887 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g58af47992 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g0ec6e30ca lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g9e3bcac55 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g222bfeeca lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gb254a2893 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g2c6c26e86 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.ge881247c3 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gfabf7e9f5 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g8c045be3a lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g8d7195543 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gfe77aae19 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.gc866c1806 lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g3e8f5731a lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g58e27be7f lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g96885856b lib/linked_rails/rdf_error.rb
linked_rails-0.0.4.pre.g1faca9643 lib/linked_rails/rdf_error.rb