module Shitceptions
@author Seth Vargo <sethvargo@gmail.com>
Constants
- EMOJIS
- VERSION
Public Class Methods
config_option(name, default_value)
click to toggle source
Set a config option for the module. This will define a getter and setter method dynamically.
@param [#to_s] name
the name of the config option
@param default_value
the default value to return if it's not set
# File lib/shitceptions.rb, line 34 def config_option(name, default_value) normalized_name = name.to_s.downcase.gsub(/[[:space:]]/, '_').to_sym instance_eval <<-RUBY def #{normalized_name}=(value) @#{normalized_name} = value end def #{normalized_name}? @#{normalized_name}.nil? ? #{default_value} : @#{normalized_name} end RUBY end
configure() { |self| ... }
click to toggle source
Configure the behavior of Shitceptions
@example
Shitceptions.configure do |c| c.enabled = false end
@example
Shitceptions.configure do |c| c.include_original_error = true end
@example
Shitceptions.enabled = false Shitceptions.include_original_error = true
# File lib/shitceptions.rb, line 23 def configure(&block) yield(self) end
shittify(klass, emoji_name)
click to toggle source
Add Shitceptions
to the given class, with the given emoji.
@param [Class] klass
the klass (most likely an error class) to apply Shitceptions to
@param [#to_s]
the name of the emoji to use
@raise [Shitceptions::ShittyArgumentError]
if the given parameter is not a Class
@raise [Shitceptions::ShittyEmojiError]
if the given emoji name does not exist
# File lib/shitceptions.rb, line 58 def shittify(klass, emoji_name) return unless enabled? raise ShittyArgumentError.new(klass) unless klass.kind_of?(Class) emoji = EMOJIS[emoji_name.to_s.downcase.gsub(/[[:space:]]/, '_').to_sym] raise ShittyEmojiError(emoji_name) unless emoji if include_original_error? klass.class_eval <<-RUBY alias_method :unshitty_to_s, :to_s def to_s "#{emoji} \#{unshitty_to_s}" end RUBY else klass.class_eval <<-RUBY alias_method :unshitty_to_s, :to_s def to_s "#{emoji} " end RUBY end end