injectedlogger 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/injectedlogger/version.rb +1 -1
- data/lib/injectedlogger.rb +18 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0701226a4844564067a36a5d01a23de9fba80a19
|
4
|
+
data.tar.gz: d6d6e8b220383059413b3d13a1541162fae8edae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eed8c42de293300f6dbaf60a03a9328e860f8ee7560d64e69e9162629c0d8faca070b56289c4ed238cdc7d786933f06e1a3af2278e89f5a471e276e0d3fac06
|
7
|
+
data.tar.gz: 4f35da7700138c6045a9b6c5f867d3a3ea8a9dcd16c83315fe61dfab44db79dc3d89c8269e8613a78dbc331229c140f0c5dd304680c84ff8e9f86816e2d999b1
|
data/README.md
CHANGED
@@ -117,6 +117,15 @@ Note that you do not need to specify the `:on` parameter for `InjectedLogger.use
|
|
117
117
|
nor `InjectedLogger.after_injection` IFF you provide a block to those methods
|
118
118
|
and want to imply `on: self`.
|
119
119
|
|
120
|
+
You can also get the logger invoking it directly on your module:
|
121
|
+
```ruby
|
122
|
+
SomeOtherGem.logger = Dependency::Logger.logger
|
123
|
+
```
|
124
|
+
or... :)
|
125
|
+
```ruby
|
126
|
+
OtherDependency.inject Dependency::Logger.logger, prefix: '[other-dependency]'
|
127
|
+
```
|
128
|
+
|
120
129
|
## Generating the gem
|
121
130
|
|
122
131
|
Both bundler and rspec are required to build the gem:
|
data/lib/injectedlogger.rb
CHANGED
@@ -37,19 +37,24 @@ module InjectedLogger
|
|
37
37
|
if on.nil?
|
38
38
|
raise InjectedLogger::DefaultInjectionBlockMissing if blk.nil?
|
39
39
|
on = blk.binding.eval 'self'
|
40
|
-
else
|
41
|
-
on = on.singleton_class unless on.is_a? Module
|
42
40
|
end
|
41
|
+
on = on.singleton_class unless on.is_a? Module
|
43
42
|
InjectedLogger.logger_known as: as, refers_to: on unless as.nil?
|
44
|
-
[
|
45
|
-
|
43
|
+
targets = [on]
|
44
|
+
targets << on.singleton_class unless on.singleton_class?
|
45
|
+
targets.each do |target|
|
46
|
+
[:inject, :inject!].each do |m|
|
47
|
+
target.define_singleton_method m do |*args, **options|
|
46
48
|
options.merge! on: on
|
47
49
|
InjectedLogger.public_send m, *args, **options
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
50
|
-
|
53
|
+
prelogger = proc do
|
51
54
|
# avoid recursion if someone calls logger in the block
|
52
|
-
|
55
|
+
targets.each do |target|
|
56
|
+
target.send :remove_method, method_name
|
57
|
+
end
|
53
58
|
unless InjectedLogger.injected? on: on
|
54
59
|
args = blk ? blk.call : nil
|
55
60
|
InjectedLogger.inject_logger args, required, on: on
|
@@ -62,13 +67,18 @@ module InjectedLogger
|
|
62
67
|
required -= thislogger.level_info[:supported]
|
63
68
|
raise InjectedLogger::UnsupportedLevels.new(required) unless required.empty?
|
64
69
|
end
|
65
|
-
|
66
|
-
|
70
|
+
targets.each do |target|
|
71
|
+
target.send :define_method, method_name do
|
72
|
+
thislogger
|
73
|
+
end
|
67
74
|
end
|
68
75
|
thislogger.after_hook.call(thislogger) if thislogger.after_hook
|
69
76
|
thislogger.send :ready
|
70
77
|
thislogger
|
71
78
|
end
|
79
|
+
targets.each do |target|
|
80
|
+
target.send :define_method, method_name, prelogger
|
81
|
+
end
|
72
82
|
end
|
73
83
|
|
74
84
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectedlogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Martinez Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|