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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76e0c6ca83edad8369e89640d915741e7c0243c8
4
- data.tar.gz: ca24a98f8a4ad30d4d3982b641b3ac7b589e4bb2
3
+ metadata.gz: 7ed2823f82e7cba6cf36cf6a49fc25a9653ce00b
4
+ data.tar.gz: 260c054c7c2d305ab0704f957ce48abbf3cf004b
5
5
  SHA512:
6
- metadata.gz: df9f53955854e96a865c6de34db278e401eb24e232d9e5e14c341c32ba7605d0c6ff2074211f6ff71ca1fe0719213be9af96b473c3a086553d4a30348853415e
7
- data.tar.gz: 1b701f337395fe562fb3c4523402f4d589ab7d504c1a1128c38164af1c44e0d2733f23a959ee0f6460bffd79e13e46e464d30144de85f3e89c3e4fda48cdb0e7
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 self, required: [:debug, :info] do
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.respond_to_missing?(method, priv)
54
+ logger.respond_to?(method, priv) || super
53
55
  end
54
56
 
55
57
  private
@@ -1,3 +1,3 @@
1
1
  module InjectedLogger
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -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 self do
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(klass, required: [], method_name: :logger, &blk)
30
- klass.send :remove_method, method_name rescue nil
31
- klass.send :define_method, method_name do
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
- klass.send :remove_method, method_name
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.3
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-04 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler