injectedlogger 0.0.10 → 0.0.11

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: f16981ff8dc874e0d132b20da815f7d11b5ccd17
4
- data.tar.gz: b10b69e4c143ab00dfb5195bcbefb2e646eafdd9
3
+ metadata.gz: e65eac7798511cef18b950cd7eed447fa009cbb4
4
+ data.tar.gz: 20c5a069668a8da8b911f9b53cfddef08144ed72
5
5
  SHA512:
6
- metadata.gz: a8a3682add57e43dd21f8f76211b0181aaec5c9b6680667f10ca26cfd2195c61d647014c31de52721a7fb4429dbfea4aaaabb1e0675b23d1b9d65ac8751329eb
7
- data.tar.gz: 020bf6172f45482b1c0e2e69ecc04a10248659d18521f1e6832a4c2b204e9799861739fa9abdca50f151806838da552e0b9cf11b93e2f592c9c04ccc7a081a84
6
+ metadata.gz: ff4cfe53d9a7882ba25280fd8f1aee00a93238ecd2cd08c7c2c63581979b7e0f574af8c7e69245bb16ad5e64b645b75385aa4e767b097c9da28ce95e2c19feaf
7
+ data.tar.gz: 2fe88af5c3c9c5787965ba2f57ad49ed4e1d5eb5c371df1e96f6225965ef778c1eb7598627b643b0cc13015e47959d5a537356dbd10fcf8b192a76890dd2ff52
data/README.md CHANGED
@@ -43,6 +43,12 @@ Inject our logger on `Dependency::Logger` and prefix the messages with `'[logger
43
43
  InjectedLogger.inject mylogger, prefix: '[logger-for-dep]', on: Dependency::Logger
44
44
  ```
45
45
 
46
+ You can also *avoid* depending on InjectedLogger if you call the `inject` method
47
+ directly on the class/module where your dependency declares the logger:
48
+ ```ruby
49
+ Dependency::Logger.inject mylogger, prefix: '[logger-for-dep]'
50
+ ```
51
+
46
52
  ### On the code where you want a logger injected:
47
53
 
48
54
  This sets up a module with a `logger` method identified as `'dependency-logger'`
@@ -40,11 +40,16 @@ module InjectedLogger
40
40
  else
41
41
  on = on.singleton_class unless on.is_a? Module
42
42
  end
43
- target = on
44
- on = as unless as.nil?
45
- target.send :define_method, method_name do
43
+ 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|
46
+ options.merge! on: on
47
+ InjectedLogger.public_send m, *args, **options
48
+ end
49
+ end
50
+ on.send :define_method, method_name do
46
51
  # avoid recursion if someone calls logger in the block
47
- target.send :remove_method, method_name
52
+ on.send :remove_method, method_name
48
53
  unless InjectedLogger.injected? on: on
49
54
  args = blk ? blk.call : nil
50
55
  InjectedLogger.inject_logger args, required, on: on
@@ -57,7 +62,7 @@ module InjectedLogger
57
62
  required -= thislogger.level_info[:supported]
58
63
  raise InjectedLogger::UnsupportedLevels.new(required) unless required.empty?
59
64
  end
60
- target.send :define_method, method_name do
65
+ on.send :define_method, method_name do
61
66
  thislogger
62
67
  end
63
68
  thislogger.after_hook.call(thislogger) if thislogger.after_hook
@@ -25,6 +25,11 @@ module InjectedLogger
25
25
  logger[on].after_hook = blk
26
26
  end
27
27
 
28
+ def self.logger_known(as:, refers_to:)
29
+ logger[as] = logger[refers_to]
30
+ end
31
+ singleton_class.send :protected, :logger_known
32
+
28
33
  class Logger
29
34
  UNKNOWN = :unknown
30
35
  LOGLEVELS = [:debug, :verbose, :notice, :info, :warn, :error, :critical, :fatal, :unknown]
@@ -1,3 +1,3 @@
1
1
  module InjectedLogger
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
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.10
4
+ version: 0.0.11
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-19 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler