pethau 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -96,4 +96,24 @@ I can type this:
96
96
 
97
97
  class Boggle
98
98
  private_attr_accessor :orf, :gin
99
- end
99
+ end
100
+
101
+
102
+ ### log\_exceptions\_from
103
+
104
+ A lot of the time tracking down error messages is a bit of a pain, trawling
105
+ through code and hoping thta somewhere jumps out that it's be useful to do this:
106
+
107
+ def foo
108
+ do_the_thing
109
+ rescue => e
110
+ logger.error [ e.message, e.backtrace ].flatten.join("\n")
111
+ raise # I still want to raise the exception, I just want to know what's up
112
+ end
113
+
114
+ Hence, log\_exceptions\_from:
115
+
116
+ def foo
117
+ do_the_thing
118
+ end
119
+ log\_exceptions\_from :foo
@@ -1,4 +1,5 @@
1
1
  require 'pethau/version'
2
2
  require 'pethau/initialize_with'
3
3
  require 'pethau/default_value_of'
4
- require 'pethau/private_attr_accessor'
4
+ require 'pethau/private_attr_accessor'
5
+ require 'pethau/log_exceptions_from'
@@ -7,7 +7,7 @@ module Pethau
7
7
  module ClassMethods
8
8
  def default_value_of attribute_name, default_value = nil, &builder
9
9
  if default_value && block_given?
10
- raise "Only provide one of default value or builder"
10
+ raise "Only provide one of default value or builder"
11
11
  end
12
12
 
13
13
  getter_with_default = "#{attribute_name}_with_default"
@@ -0,0 +1,30 @@
1
+ module Pethau
2
+ module LogExceptionsFrom
3
+ def self.included into
4
+ into.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def log_exceptions_from *method_names
9
+ method_names.each do |method_name|
10
+ method_with_exception_logging = "#{method_name}_with_exception_logging"
11
+ method_without_exception_logging = "#{method_name}_without_exception_logging"
12
+
13
+ alias_method method_without_exception_logging, method_name
14
+ define_method method_with_exception_logging do |*args|
15
+ begin
16
+ send method_without_exception_logging, *args
17
+ rescue Exception => e
18
+ raise unless defined? logger
19
+ logger.error [ e.message, e.backtrace ].flatten.join("\n")
20
+ raise
21
+ end
22
+ end
23
+ alias_method method_name, method_with_exception_logging
24
+ end
25
+ end
26
+ private :log_exceptions_from
27
+ end
28
+ end
29
+ end
30
+
@@ -1,3 +1,3 @@
1
1
  module Pethau
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pethau
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-25 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Extracting a bunch of code that we use across our projects. In less awesome
15
15
  teams this would be the utility package.
@@ -21,6 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - lib/pethau/default_value_of.rb
23
23
  - lib/pethau/initialize_with.rb
24
+ - lib/pethau/log_exceptions_from.rb
24
25
  - lib/pethau/private_attr_accessor.rb
25
26
  - lib/pethau/version.rb
26
27
  - lib/pethau.rb