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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e65eac7798511cef18b950cd7eed447fa009cbb4
4
- data.tar.gz: 20c5a069668a8da8b911f9b53cfddef08144ed72
3
+ metadata.gz: 0701226a4844564067a36a5d01a23de9fba80a19
4
+ data.tar.gz: d6d6e8b220383059413b3d13a1541162fae8edae
5
5
  SHA512:
6
- metadata.gz: ff4cfe53d9a7882ba25280fd8f1aee00a93238ecd2cd08c7c2c63581979b7e0f574af8c7e69245bb16ad5e64b645b75385aa4e767b097c9da28ce95e2c19feaf
7
- data.tar.gz: 2fe88af5c3c9c5787965ba2f57ad49ed4e1d5eb5c371df1e96f6225965ef778c1eb7598627b643b0cc13015e47959d5a537356dbd10fcf8b192a76890dd2ff52
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:
@@ -1,3 +1,3 @@
1
1
  module InjectedLogger
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -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
- [:inject, :inject!].each do |m|
45
- on.define_singleton_method m do |*args, **options|
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
- on.send :define_method, method_name do
53
+ prelogger = proc do
51
54
  # avoid recursion if someone calls logger in the block
52
- on.send :remove_method, method_name
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
- on.send :define_method, method_name do
66
- thislogger
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.11
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-23 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler