timber 2.0.10 → 2.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: d8f4370bada35338e39a28f00a5c1530175e285a
4
- data.tar.gz: b15a814d3c4d6fdd557f7a509bc2452fd86a99ff
3
+ metadata.gz: 7c92caecf236aae6f47636ea5646c3822a31fa51
4
+ data.tar.gz: df5d9292f27cba1fa0405a919002434eb4d91bdf
5
5
  SHA512:
6
- metadata.gz: eb512f1759ec51bcbeb28b3cfbbb193dc805cc55c403e48d1fa519fbed4012bebd00802d8467a8af2a0cc56dc5ba50bb27eb78109626d27b00e77e3f74994c58
7
- data.tar.gz: b240d0b6062fc042676be8ab4e9fa89622efad45ccdee3514b102b53d83f0879a829617dbc9eac99372e22466030e088ef948a6bc80ad6dded4019cd031ecac8
6
+ metadata.gz: 8d1617ab8a68cb5ceef91036f196cc1fecd97f09236a2a06319dbb69c1b3e9a9c606ba98a214dc266e73ccc5f277e454939fb2acf2e19da9e6259ad8ce8005aa
7
+ data.tar.gz: ed1da42f194b9ce03c5e07c7b073306b1de59e0715e9721f3859efdb2e1a974dcb3de76a86c7271b6f38831eed2036bec52621d4b95f050b6454913f6d3ae11d
@@ -8,22 +8,30 @@ module Timber
8
8
  end
9
9
 
10
10
  def call(env)
11
+ debug { "#{self.class.name} - Starting user context" }
11
12
  user_hash = get_user_hash(env)
12
13
  if user_hash
14
+ debug { "#{self.class.name} - User hash found: #{user_hash.inspect}" }
13
15
  context = Contexts::User.new(user_hash)
14
16
  CurrentContext.with(context) do
15
17
  @app.call(env)
16
18
  end
17
19
  else
20
+ debug { "#{self.class.name} - User hash not found" }
18
21
  @app.call(env)
19
22
  end
20
23
  end
21
24
 
22
25
  private
23
26
  def get_user_hash(env)
24
- if env['warden']
25
- get_user_hash_from_object(env['warden'].user)
26
- elsif env['omniauth.auth']
27
+ get_omniauth_user_hash(env) ||
28
+ get_warden_user_hash(env) ||
29
+ nil
30
+ end
31
+
32
+ def get_omniauth_user_hash(env)
33
+ if env['omniauth.auth']
34
+ debug { "#{self.class.name} - Omniauth hash present #{env['omniauth.auth'].inspect}" }
27
35
  auth_hash = env['omniauth.auth']
28
36
  info = auth_hash['info']
29
37
 
@@ -33,23 +41,42 @@ module Timber
33
41
  email: info['email']
34
42
  }
35
43
  else
44
+ debug { "#{self.class.name} - Omniauth hash not present" }
36
45
  nil
37
46
  end
38
47
  end
39
48
 
40
- def get_user_hash_from_object(user)
41
- {
42
- id: user_id(user),
43
- name: user_name(user),
44
- email: user_email(user)
45
- }
49
+ def get_warden_user_hash(env)
50
+ if env['warden']
51
+ debug { "#{self.class.name} - Warden object present #{env['warden'].inspect}" }
52
+ user = env['warden'].user
53
+ if user
54
+ debug { "#{self.class.name} - Warden user object #{env['warden'].user.inspect}" }
55
+ id = try_user_id(user)
56
+ name = try_user_name(user)
57
+ email = try_user_email(user)
58
+
59
+ if id || name || email
60
+ debug { "#{self.class.name} - At least one warden user attribute was present" }
61
+ {id: id, name: name, email: email}
62
+ else
63
+ debug { "#{self.class.name} - No warden user attributes were present" }
64
+ nil
65
+ end
66
+ else
67
+ debug { "#{self.class.name} - Warden user object not present, not logged in" }
68
+ nil
69
+ end
70
+ else
71
+ nil
72
+ end
46
73
  end
47
74
 
48
- def user_id(user)
75
+ def try_user_id(user)
49
76
  user.respond_to?(:id) ? user.id : nil
50
77
  end
51
78
 
52
- def user_name(user)
79
+ def try_user_name(user)
53
80
  if user.respond_to?(:name) && user.name.is_a?(String)
54
81
  user.name
55
82
  elsif user.respond_to?(:first_name) && user.first_name.is_a?(String) && user.respond_to?(:last_name) && user.last_name.is_a?(String)
@@ -59,13 +86,24 @@ module Timber
59
86
  end
60
87
  end
61
88
 
62
- def user_email(user)
89
+ def try_user_email(user)
63
90
  if user.respond_to?(:email) && user.email.is_a?(String)
64
91
  user.email
65
92
  else
66
93
  nil
67
94
  end
68
95
  end
96
+
97
+ def debug_logger
98
+ Timber::Config.instance.debug_logger
99
+ end
100
+
101
+ def debug(&block)
102
+ if debug_logger
103
+ message = yield
104
+ debug_logger.debug(message)
105
+ end
106
+ end
69
107
  end
70
108
  end
71
109
  end
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "2.0.10"
2
+ VERSION = "2.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack