call_logger 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86ff0a5285a0155ffe5c9bf31253c7208ec6d4e22b32e04388bada594abd3726
4
- data.tar.gz: 97c3aba959d1d3864d667213f4a6709e599669323abb453185e834982856cc60
3
+ metadata.gz: 1be10df846b98a0cc41e280cb479f001e13395f9b29ccf95957d8e6972ec488b
4
+ data.tar.gz: e4fa1c60c89dd8a1527569b5d0bca309495fd68d95d0439c3abdf065ee6ce572
5
5
  SHA512:
6
- metadata.gz: 8781225032feeb50ecef93f2e1e2753b16762fe3ea50f3da1ad01189ab0e7e23932fa8b2abf8c483bf3bcdbf2143709979bdedf66f75284fb247be32f0e184a1
7
- data.tar.gz: b0cca1e74771fc882fc4645b691bbbbdd8f53e2e6a799ac59e81ebbc02e537214f08269df2782f9b7f1804c62400bf3d7cb6bf10fd38d445ee26b96305fa7791
6
+ metadata.gz: dc4ea0468e82e0db6237a116a3c5a7956cc76a4049769d814f728cb709784077a8494e2daaebedc22b987707045ecddf276c7ceeb007f6548513dd5a4e481bd5
7
+ data.tar.gz: a339bee163ba14de107ce8e24f64667ba56ad0d4260800a0368f9777485fae39426c77710dc4b75e61b6cfb58a633c78fbf3fa2dc3f11f9d6e4f2516feeabb14
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- call_logger (0.2.0)
4
+ call_logger (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -13,17 +13,25 @@ class Calculator
13
13
  log def div(a, b)
14
14
  a/b
15
15
  end
16
+
17
+ log_class def self.info(msg)
18
+ "Showing: #{msg}"
19
+ end
16
20
  end
17
21
 
18
22
  Calculator.new.times(3,4)
19
- # times(3, 4)
20
- # times => 6
23
+ # Calculator#times(3, 4)
24
+ # Calculator#times => 6
21
25
  # => 7
22
26
 
23
27
  Calculator.new.div(3,0)
24
- # div(3, 0)
25
- # div !! divided by 0
28
+ # Calculator#div(3, 0)
29
+ # Calculator#div !! divided by 0
26
30
  # ZeroDivisionError: divided by 0
31
+
32
+ Calculator.info("hello!")
33
+ # Calculator.info(hello)
34
+ # Calculator.info => "Showing: hello"
27
35
  ```
28
36
 
29
37
  ## Installation
@@ -70,6 +78,19 @@ class Calculator
70
78
  end
71
79
  ```
72
80
 
81
+ If you want to log class method calls, prepend them with `.log_class`:
82
+
83
+ ```
84
+ class Calculator
85
+ include CallLogger
86
+
87
+ log_class def self.times(a, b)
88
+ a*b
89
+ end
90
+ end
91
+ ```
92
+
93
+
73
94
  ### Configuration
74
95
 
75
96
  There are two pluggable components: `Logger` and `Formatter`. `Formatter` preperes messages to be printed and `Logger` sents them to the
@@ -90,11 +111,13 @@ end
90
111
 
91
112
  ## TODO
92
113
 
93
- * [] class methods
114
+ * [+] class methods
94
115
  * [] multiple method names
95
116
  * [] handle blocks
96
117
  * [] logging all methods defined in the class
97
118
  * [] doc: Rails integration
119
+ * [] doc: API docs
120
+ * [] infra: travis
98
121
 
99
122
  ## Development
100
123
 
@@ -4,7 +4,6 @@ module CallLogger
4
4
  "#{method}(#{args.join(', ')})"
5
5
  end
6
6
 
7
- # args?
8
7
  def after(method, result)
9
8
  "#{method} => #{result}"
10
9
  end
@@ -1,3 +1,3 @@
1
1
  module CallLogger
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/call_logger.rb CHANGED
@@ -20,23 +20,33 @@ module CallLogger
20
20
  end
21
21
  configure # set defaults
22
22
 
23
- def log(method, args, &block)
24
- logger = ::CallLogger.configuration.logger
25
- formatter = ::CallLogger.configuration.formatter
26
- method_wrapper = ::CallLogger::MethodWrapper.new(
27
- logger: logger, formatter: formatter
28
- )
29
- method_wrapper.call(method, args, &block)
30
- end
31
23
 
32
24
  module ClassMethods
33
25
  def log(method)
34
26
  alias_method "#{method}_without_log", method
35
27
  define_method method do |*args|
36
- log(method, args) do
28
+ self.class.do_log("#{self.class}##{method}", args) do
29
+ send("#{method}_without_log", *args)
30
+ end
31
+ end
32
+ end
33
+
34
+ def log_class(method)
35
+ singleton_class.alias_method "#{method}_without_log", method
36
+ singleton_class.define_method method do |*args|
37
+ do_log("#{self}.#{method}", args) do
37
38
  send("#{method}_without_log", *args)
38
39
  end
39
40
  end
40
41
  end
42
+
43
+ def do_log(method, args, &block)
44
+ logger = ::CallLogger.configuration.logger
45
+ formatter = ::CallLogger.configuration.formatter
46
+ method_wrapper = ::CallLogger::MethodWrapper.new(
47
+ logger: logger, formatter: formatter
48
+ )
49
+ method_wrapper.call(method, args, &block)
50
+ end
41
51
  end
42
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: call_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Rzasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-22 00:00:00.000000000 Z
11
+ date: 2018-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler