Module: Weechat::Utilities
- Defined in:
- lib/weechat/utilities.rb
Class Method Summary collapse
- .apply_transformation(property, value, transformations) ⇒ Object
- .evaluate_call ⇒ Object
- .format_exception(e) ⇒ Object
- .safe_call ⇒ Object
Class Method Details
.apply_transformation(property, value, transformations) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/weechat/utilities.rb', line 40 def self.apply_transformation(property, value, transformations) transformation = transformations.find {|properties, transformations| properties.any? {|prop| case prop when Regexp prop =~ property.to_s when String, Symbol prop.to_sym == property.to_sym else false end } } if transformation transformation[1].call(value) else value end end |
.evaluate_call ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/weechat/utilities.rb', line 23 def self.evaluate_call begin yield rescue Weechat::Exception::WEECHAT_RC_OK return Weechat::WEECHAT_RC_OK rescue Weechat::Exception::WEECHAT_RC_OK_EAT return Weechat::WEECHAT_RC_OK_EAT rescue Weechat::Exception::WEECHAT_RC_ERROR return Weechat::WEECHAT_RC_ERROR rescue => e format_exception(e) return Weechat::WEECHAT_RC_ERROR end return Weechat::WEECHAT_RC_OK end |
.format_exception(e) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/weechat/utilities.rb', line 3 def self.format_exception(e) prefix = Weechat.prefix("error") line1 = e.backtrace[0] + ": " + e. + " (" + e.class.name + ")" backtrace = " " + e.backtrace[1..-1].join("\n ") Weechat.puts("#{prefix}error in evaluated call: #{line1}") Weechat.puts("#{prefix}#{backtrace}") end |