injectedlogger 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/injectedlogger/logger.rb +3 -1
- data/lib/injectedlogger/version.rb +1 -1
- data/lib/injectedlogger.rb +6 -6
- 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: 7ed2823f82e7cba6cf36cf6a49fc25a9653ce00b
|
4
|
+
data.tar.gz: 260c054c7c2d305ab0704f957ce48abbf3cf004b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2ca8524827fbff3ff2f53dec3c9a192e236aee3e8de1c4c18ade2f75d0c3728ce5e2f053f431dd8b5a2d4556c73e21cf82d500004b69e3f1d39cf5dc797af0a
|
7
|
+
data.tar.gz: 208518022caff1c31ffa758717fcf08e38c21d0bb7a6a81c7f92807af260489b660f30c07096d906f31f574d43aba5469fbfc6121dcab75afea2d7200b14f928
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ It will try to support as many methods and levels as the underlying object suppo
|
|
7
7
|
## Usage
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
logger = InjectedLogger.use somelogger
|
10
|
+
logger = InjectedLogger::Logger.use somelogger
|
11
11
|
raise 'No info :(' unless logger.level_info[:supported].include? :info
|
12
12
|
logger.info 'You now have a logger!'
|
13
13
|
```
|
@@ -16,7 +16,7 @@ or you can set-up a default injection for your logger in case no one else sets i
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
module MyLogger
|
19
|
-
InjectedLogger.inject
|
19
|
+
InjectedLogger.inject required: [:debug, :info] do
|
20
20
|
require 'logger'
|
21
21
|
{ logger: Logger.new(STDERR), prefix: '[mylogger]' }
|
22
22
|
end
|
@@ -46,10 +46,12 @@ module InjectedLogger
|
|
46
46
|
|
47
47
|
def method_missing(method, *args, &blk)
|
48
48
|
logger.send method, *args, &blk
|
49
|
+
rescue NoMethodError
|
50
|
+
super
|
49
51
|
end
|
50
52
|
|
51
53
|
def respond_to_missing?(method, priv = false)
|
52
|
-
logger.
|
54
|
+
logger.respond_to?(method, priv) || super
|
53
55
|
end
|
54
56
|
|
55
57
|
private
|
data/lib/injectedlogger.rb
CHANGED
@@ -6,7 +6,7 @@ module InjectedLogger
|
|
6
6
|
# inject a default logger in case no one has set one for you:
|
7
7
|
#
|
8
8
|
# module MyLogger
|
9
|
-
# InjectedLogger.inject
|
9
|
+
# InjectedLogger.inject do
|
10
10
|
# require 'logger'
|
11
11
|
# # logger is required, the rest are other use() params
|
12
12
|
# { logger: Logger.new(STDERR), prefix: '[mylogger]', ... }
|
@@ -26,9 +26,10 @@ module InjectedLogger
|
|
26
26
|
# logger method is called, so that it does not 'require' anything if it is not
|
27
27
|
# needed. :)
|
28
28
|
|
29
|
-
def self.inject(
|
30
|
-
|
31
|
-
|
29
|
+
def self.inject(on: nil, required: [], method_name: :logger, &blk)
|
30
|
+
on = blk.binding.eval 'self' unless on
|
31
|
+
on = on.singleton_class unless on.is_a? Module
|
32
|
+
on.send :define_method, method_name do
|
32
33
|
unless InjectedLogger::Logger.in_use?
|
33
34
|
args = blk.call
|
34
35
|
logger = args.delete :logger
|
@@ -41,8 +42,7 @@ module InjectedLogger
|
|
41
42
|
required.uniq!
|
42
43
|
required -= InjectedLogger::Logger.level_info[:supported]
|
43
44
|
raise InjectedLogger::UnsupportedLevels.new(required) if not required.empty?
|
44
|
-
|
45
|
-
klass.send :define_method, method_name do
|
45
|
+
on.send :define_method, method_name do
|
46
46
|
InjectedLogger::Logger
|
47
47
|
end
|
48
48
|
InjectedLogger::Logger
|
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.4
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|