logrithm 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: e7cc04ee6f656f889e885abb7b2fad8239812ab1
4
- data.tar.gz: 2877580cfca21aad92a18e093893f7c1321ea14d
3
+ metadata.gz: 86cba65ebff7f5967d1adbfb48940c461ba76511
4
+ data.tar.gz: 7a10a6397937fa1500de32f65123776e27003ed5
5
5
  SHA512:
6
- metadata.gz: d7277a5c320908ebcb6a93ec0bc9d3aecb5997772cf60acecec31506b310042a8e8282ede7bbf614058de03ad83752fa0514106342e0efcb9fd3801c645de8d4
7
- data.tar.gz: ee5794ce6f162305632923a6b78804e2302bee0c80c76ee552fca830cf6f081817ba17d4f08b92326ae522cd59fe66d80e745b97cef343dccf0ab8a47cd793b6
6
+ metadata.gz: b5a0d7e43974711935fe2e8f5faefc7c5e9dd663fe3ff683f9c4b810cb0528c8478880841c8bf7126fcaa58a10008e0386b27ec36a46f475d0943c3040eb5054
7
+ data.tar.gz: 445167639261857670d8e2f72cbc55ae801d4e3abe5116410d0f935f0ef4805465780edbfd40d23bfc268544275490c5e5e0eae41d6b43f576832ddaca6ce1b3
@@ -23,7 +23,7 @@ module Logrithm
23
23
  klazz = obj.class.ancestors.inject(nil) do |memo, k|
24
24
  memo || Utils::Helpers.constantize(k, Logrithm::Spitters)
25
25
  end || Utils::Helpers.constantize(:string, Logrithm::Spitters)
26
- yield klazz.new(obj).formatted
26
+ yield klazz.new(obj).formatted unless empty?(obj)
27
27
  end
28
28
  end
29
29
 
data/lib/logrithm/log.rb CHANGED
@@ -7,18 +7,7 @@ module Logrithm
7
7
  include Kungfuig
8
8
 
9
9
  JOINER = "#{$/} #{option(:log, :joiners, :objects) || '⮩ '}".freeze
10
-
11
- def self.log(message)
12
- if $♯
13
- puts "Self: [#{$♯}], Message: [#{message}]."
14
- else
15
- # idx = caller.index { |s| s.include? __FILE__ } to work inside pry
16
- Utils::Syringe.inject(*Utils::Helpers.dirty_lookup_class_method(*caller.first[/\A(.+):(\d+)(?=:in)/].split(/:(?=\d+\z)/)))
17
- puts "Message: [#{message}]."
18
- end
19
- rescue
20
- puts "Message: [#{message}]."
21
- end
10
+ USE_GLOBAL_SELF = option(:log, :global_self) || false
22
11
 
23
12
  def initialize(log = nil, **params)
24
13
  [
@@ -54,6 +43,21 @@ module Logrithm
54
43
 
55
44
  %i(debug info warn error fatal).each do |m|
56
45
  define_method(m) do |*args, **extended|
46
+ # rubocop:disable Lint/HandleExceptions
47
+ # rubocop:disable Style/RescueModifier
48
+ if USE_GLOBAL_SELF && $♯.nil?
49
+ caller_line = caller.detect do |line|
50
+ Logrithm.rails? ? line.start_with?(Rails.root.to_s) : !line.start_with?(__dir__)
51
+ end
52
+ cf = caller_line[/\A(.+):(\d+)(?=:in)/].split(/:(?=\d+\z)/)
53
+ if cf.is_a?(Array) && cf.first.is_a?(String)
54
+ Utils::Syringe.inject(*Utils::Helpers.dirty_lookup_class_method(*cf))
55
+ end
56
+ end rescue nil # SUPPRESS
57
+ # rubocop:enable Style/RescueModifier
58
+ # rubocop:enable Lint/HandleExceptions
59
+ args << $♯ if $♯ # global constant storing the object
60
+
57
61
  logger.public_send m, (args.length == 1 && extended.empty? ? args.first : [*args, **extended])
58
62
  end
59
63
  end
@@ -12,8 +12,8 @@ module Logrithm
12
12
  def dirty_lookup_class_method(file, lineno)
13
13
  content = File.readlines(file)[0..lineno.to_i].reverse
14
14
  result = content.each_with_object(method: nil, ns: []) do |line, memo|
15
- (memo[:method] ||= line[/\A\s*def\s*(?<method>\w+)/, :method]) &&
16
- (memo[:ns] << line[/\A\s*(?:class|module)\s*(?<ns>\w+)/, :ns])
15
+ (memo[:method] ||= line[/\A\s*def\s+(?<method>\w+)/, :method]) &&
16
+ (memo[:ns] << line[/\A\s*(?:class|module)\s+(?<ns>\w+)/, :ns])
17
17
  end
18
18
 
19
19
  [const_get(result[:ns].compact.reverse.join('::')), result[:method]]
@@ -1,3 +1,3 @@
1
1
  module Logrithm
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logrithm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin