Sha256: 96b0f1600181e4e688a3427e22292e985ff7eb8f3ffd57d38d8c9b1f7ddbb1bd

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'i18n'
require 'active_support'
require 'active_support/core_ext'
require 'smart_error/version'

I18n.config.available_locales = :en

module SmartError
  mattr_accessor :base_url
  @@base_url = nil

  mattr_accessor :excption_error_code
  @@excption_error_code = 1000

  mattr_accessor :model_error_code
  @@model_error_code = 1010

  # It accept [:first, :last, :sentence]
  mattr_accessor :model_error_message
  @@model_error_message = :first

  def self.handle(error, options = nil)
    if error.is_a?(Integer)
      SmartError::CustomError.new(error, options)
    elsif error.is_a?(Exception)
      SmartError::ExceptionError.new(error, options)
    elsif error.is_a?(ApplicationRecord) || error.is_a?(ActiveRecord)
      SmartError::ModelError.new(error, options)
    else
      SmartError::CustomeError.new(1000, options)
    end
  end

  def self.config
    yield self
  end
end

require 'smart_error/base_error'
require 'smart_error/model_error'
require 'smart_error/custom_error'
require 'smart_error/exception_error'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smart_error-1.0.2 lib/smart_error.rb
smart_error-1.0.1 lib/smart_error.rb
smart_error-1.0.0 lib/smart_error.rb