Sha256: 254393d02230e98c0d0f55585294fe91a2bfa584028398b29c0a2a3324282ca2

Contents?: true

Size: 531 Bytes

Versions: 1

Compression:

Stored size: 531 Bytes

Contents

module Ncn
  class Error < StandardError
    RepoIsEmpty = Class.new(self)
    NoteNotFound = Class.new(self)
    NonValidNoteId = Class.new(self)

    attr_reader :context

    def initialize(context = {})
      @context = context
    end

    def message
      context[:message] || default_message
    end

    def to_s
      message
    end

    def to_json
      JSON.generate(context)
    end

    private

    def default_message
      self.class.name.split("::").last.gsub(/(?!\b)([A-Z])/, ' \1').downcase
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ncn-0.1.0 lib/ncn/error.rb