hatchet 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hatchet.rb CHANGED
@@ -161,6 +161,16 @@ module Hatchet
161
161
  @config ||= Configuration.new
162
162
  end
163
163
 
164
+ # Internal: Hook that extends the class with Hatchet when it is included.
165
+ #
166
+ # klass - The klass that Hatchet was included into.
167
+ #
168
+ # Returns nothing.
169
+ #
170
+ def self.included(klass)
171
+ klass.extend Hatchet
172
+ end
173
+
164
174
  end
165
175
 
166
176
  # If we are running in a Rails environment include the Hatchet::Railtie class.
@@ -168,7 +168,7 @@ module Hatchet
168
168
  def context(host)
169
169
  if host.inspect == 'main'
170
170
  'main'
171
- elsif host.class == Module
171
+ elsif [Module, Class].include? host.class
172
172
  host
173
173
  else
174
174
  host.class
@@ -4,6 +4,6 @@ module Hatchet
4
4
 
5
5
  # Public: The version of Hatchet.
6
6
  #
7
- VERSION = '0.0.15'
7
+ VERSION = '0.0.16'
8
8
 
9
9
  end
@@ -0,0 +1,56 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ class IncludeExample
6
+ include Hatchet
7
+
8
+ def self.class_log
9
+ log.info { 'class log' }
10
+ end
11
+
12
+ def instance_log
13
+ log.info { 'instance log' }
14
+ end
15
+
16
+ end
17
+
18
+ describe 'hatchet include behavior' do
19
+ let(:appender) { StoringAppender.new }
20
+
21
+ before do
22
+ Hatchet.configure do |config|
23
+ config.reset!
24
+ config.appenders << appender
25
+ end
26
+ end
27
+
28
+ describe 'logging from class methods' do
29
+ before do
30
+ IncludeExample.class_log
31
+ end
32
+
33
+ it 'logs a method from the class' do
34
+ msg = appender.messages.last
35
+
36
+ assert_equal :info, msg.level
37
+ assert_equal IncludeExample, msg.context
38
+ assert_equal 'class log', msg.message.to_s
39
+ end
40
+ end
41
+
42
+ describe 'logging from instance methods' do
43
+ before do
44
+ IncludeExample.new.instance_log
45
+ end
46
+
47
+ it 'logs a method from the instance' do
48
+ msg = appender.messages.last
49
+
50
+ assert_equal :info, msg.level
51
+ assert_equal IncludeExample, msg.context
52
+ assert_equal 'instance log', msg.message.to_s
53
+ end
54
+ end
55
+ end
56
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatchet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
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: 2012-08-05 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Logging library that provides the ability to add class/module specific
15
15
  filters
@@ -36,6 +36,7 @@ files:
36
36
  - spec/helpers/logger_double.rb
37
37
  - spec/helpers/storing_appender.rb
38
38
  - spec/helpers/test_formatter.rb
39
+ - spec/include_spec.rb
39
40
  - spec/level_manager_spec.rb
40
41
  - spec/logger_appender_spec.rb
41
42
  - spec/logger_spec.rb
@@ -57,12 +58,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
58
  - - ! '>='
58
59
  - !ruby/object:Gem::Version
59
60
  version: '0'
61
+ segments:
62
+ - 0
63
+ hash: 569280193996851270
60
64
  required_rubygems_version: !ruby/object:Gem::Requirement
61
65
  none: false
62
66
  requirements:
63
67
  - - ! '>='
64
68
  - !ruby/object:Gem::Version
65
69
  version: '0'
70
+ segments:
71
+ - 0
72
+ hash: 569280193996851270
66
73
  requirements: []
67
74
  rubyforge_project:
68
75
  rubygems_version: 1.8.17
@@ -75,6 +82,7 @@ test_files:
75
82
  - spec/helpers/logger_double.rb
76
83
  - spec/helpers/storing_appender.rb
77
84
  - spec/helpers/test_formatter.rb
85
+ - spec/include_spec.rb
78
86
  - spec/level_manager_spec.rb
79
87
  - spec/logger_appender_spec.rb
80
88
  - spec/logger_spec.rb