Sha256: c9f5fda3b4cd9aa483c8dd4c854f4e2834ec6308c7af65dcbf4f7c157404f26f
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
# encoding: utf-8 require_relative "messages" module Hexx module Helpers # @api hide # The module declares instance helper methods to provide validations module Exceptions extend ActiveSupport::Concern include ActiveModel::Validations include Messages # @api hide # Class helper methods module ClassMethods def raises(*names) fail ArgumentError if (types = names.flatten.map(&:to_s)) == [] types.each { |type| add_exception(type) } end private def add_exception(type) check type class_eval "class #{ type } < StandardError; end" end def check(type) return if type[/([A-Z][a-z]+)+/] fail TypeError.new( %(Wrong exception name "#{ type }". Use words in camel-case only.) ) end end def on_error(messages) messages.map(&:text).each { |text| errors.add :base, text } fail Hexx::ServiceInvalid.new(self) end def escape yield rescue Hexx::ServiceInvalid => err raise err rescue => err errors.add :base, err.message raise Hexx::ServiceInvalid.new(self) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hexx-7.1.0 | lib/hexx/helpers/exceptions.rb |
hexx-7.0.1 | lib/hexx/helpers/exceptions.rb |
hexx-7.0.0 | lib/hexx/helpers/exceptions.rb |