current_session 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/current_session/auth_method.rb +44 -0
- data/lib/current_session/base.rb +8 -10
- data/lib/current_session/interface.rb +2 -2
- data/lib/current_session/{repository.rb → session_method.rb} +5 -1
- data/lib/current_session/version.rb +1 -1
- data/lib/current_session.rb +2 -3
- metadata +4 -5
- data/lib/current_session/auth.rb +0 -19
- data/lib/current_session/raise_not_implemented_error.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13ac22af37f6aa5545fb02c46c729473b043b67c4073c9b481015c422c7d5927
|
4
|
+
data.tar.gz: c2bd6c1da99e69a41ecadf263f2c0219633d45da7cb723476d4fb8904c8344ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e193a8e670f0f684dc509193b0d1ada1f092551b312cc3032527520e8c1957c413a2bd77c2637556498b5f898b49974839d4752e1d09792dda68a73e357cc5f
|
7
|
+
data.tar.gz: 4cd6ca157c873142fc4c43c9a14c2a16e7f8487364d94c116204e7aca36d9b005c5f05d44e80aa3264885363d08e74271d4d442c786d7359fd44c01ee47225d3
|
data/.rubocop.yml
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CurrentSession
|
4
|
+
#
|
5
|
+
# Base class for providing auth methods
|
6
|
+
#
|
7
|
+
class AuthMethod
|
8
|
+
class_attribute :user_class
|
9
|
+
|
10
|
+
class FindBy < self
|
11
|
+
def call(&block)
|
12
|
+
find_by_auth.try(&block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class FindOrCreateBy < self
|
17
|
+
def call(&block)
|
18
|
+
find_or_create_by_auth.try(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.new_auth_class(auth_methods_module)
|
23
|
+
new_auth_class =
|
24
|
+
if auth_methods_module.method_defined?(:find_by_auth)
|
25
|
+
Class.new(CurrentSession::AuthMethod::FindBy) { include auth_methods_module }
|
26
|
+
elsif auth_methods_module.method_defined?(:find_or_create_by_auth)
|
27
|
+
Class.new(CurrentSession::AuthMethod::FindOrCreateBy) { include auth_methods_module }
|
28
|
+
else
|
29
|
+
fail NotImplementedError, "You must implement find_by_auth or find_or_create_by_auth"
|
30
|
+
end
|
31
|
+
new_auth_class.user_class = user_class
|
32
|
+
new_auth_class
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(request)
|
36
|
+
@request = request
|
37
|
+
end
|
38
|
+
attr_reader :request
|
39
|
+
|
40
|
+
def auth
|
41
|
+
request.env["omniauth.auth"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/current_session/base.rb
CHANGED
@@ -6,7 +6,6 @@ module CurrentSession
|
|
6
6
|
#
|
7
7
|
class Base < ActiveSupport::CurrentAttributes
|
8
8
|
include CurrentSession::Interface
|
9
|
-
include CurrentSession::RaiseNotImplementedError
|
10
9
|
attribute :current_user
|
11
10
|
|
12
11
|
class << self
|
@@ -22,30 +21,29 @@ module CurrentSession
|
|
22
21
|
Time.current
|
23
22
|
end
|
24
23
|
|
25
|
-
def session_methods=(
|
26
|
-
@
|
24
|
+
def session_methods=(session_methods)
|
25
|
+
@session_methods = session_methods
|
26
|
+
@session_class = CurrentSession::SessionMethod.new_session_class(session_methods)
|
27
27
|
end
|
28
28
|
|
29
29
|
def session_methods(&block)
|
30
30
|
if block
|
31
|
-
session_methods = Module.new(&block)
|
32
|
-
@
|
33
|
-
@session_methods = session_methods
|
31
|
+
@session_methods = Module.new(&block)
|
32
|
+
@session_class = CurrentSession::SessionMethod.new_session_class(session_methods)
|
34
33
|
else
|
35
34
|
@session_methods
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
38
|
def auth_methods=(auth_methods_module)
|
40
|
-
@auth_class =
|
39
|
+
@auth_class = CurrentSession::AuthMethod.new_auth_class(auth_methods_module)
|
41
40
|
end
|
42
41
|
|
43
42
|
def auth_methods(&block)
|
44
43
|
if block
|
45
|
-
auth_methods = Module.new(&block)
|
46
|
-
@auth_class =
|
44
|
+
@auth_methods = Module.new(&block)
|
45
|
+
@auth_class = CurrentSession::AuthMethod.new_auth_class(auth_methods)
|
47
46
|
@auth_class.user_class = user_class
|
48
|
-
@auth_methods = auth_methods
|
49
47
|
else
|
50
48
|
@auth_methods
|
51
49
|
end
|
@@ -20,7 +20,7 @@ module CurrentSession
|
|
20
20
|
|
21
21
|
def create(request)
|
22
22
|
auth = @auth_class.new(request)
|
23
|
-
auth.
|
23
|
+
auth.call do |user|
|
24
24
|
auth.update(user)
|
25
25
|
session_repository(request).update_session_token(user)
|
26
26
|
end
|
@@ -37,7 +37,7 @@ module CurrentSession
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def session_repository(request)
|
40
|
-
@
|
40
|
+
@session_class.new(
|
41
41
|
request: request,
|
42
42
|
user_class: user_class,
|
43
43
|
session_token_class: session_token_class,
|
@@ -4,7 +4,11 @@ module CurrentSession
|
|
4
4
|
#
|
5
5
|
# Base class for processing to get session_token from request.session
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class SessionMethod
|
8
|
+
def self.new_session_class(session_methods)
|
9
|
+
Class.new(CurrentSession::SessionMethod) { include session_methods }
|
10
|
+
end
|
11
|
+
|
8
12
|
def initialize(current_time:, request:, user_class:, session_token_class:)
|
9
13
|
@current_time = current_time
|
10
14
|
@request = request
|
data/lib/current_session.rb
CHANGED
@@ -10,9 +10,8 @@ module CurrentSession
|
|
10
10
|
extend ActiveSupport::Autoload
|
11
11
|
autoload :Base
|
12
12
|
autoload :Interface
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :RaiseNotImplementedError
|
13
|
+
autoload :AuthMethod
|
14
|
+
autoload :SessionMethod
|
16
15
|
autoload :SessionMethods
|
17
16
|
|
18
17
|
def self.key(user_class)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: current_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa (Aileron inc)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -146,11 +146,10 @@ files:
|
|
146
146
|
- bin/setup
|
147
147
|
- current_session.gemspec
|
148
148
|
- lib/current_session.rb
|
149
|
-
- lib/current_session/
|
149
|
+
- lib/current_session/auth_method.rb
|
150
150
|
- lib/current_session/base.rb
|
151
151
|
- lib/current_session/interface.rb
|
152
|
-
- lib/current_session/
|
153
|
-
- lib/current_session/repository.rb
|
152
|
+
- lib/current_session/session_method.rb
|
154
153
|
- lib/current_session/session_methods.rb
|
155
154
|
- lib/current_session/session_methods/active_record_session.rb
|
156
155
|
- lib/current_session/session_methods/env_session.rb
|
data/lib/current_session/auth.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
#
|
5
|
-
# Base class for providing auth methods
|
6
|
-
#
|
7
|
-
class Auth
|
8
|
-
class_attribute :user_class
|
9
|
-
|
10
|
-
def initialize(request)
|
11
|
-
@request = request
|
12
|
-
end
|
13
|
-
attr_reader :request
|
14
|
-
|
15
|
-
def auth
|
16
|
-
request.env["omniauth.auth"]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
#
|
5
|
-
# Class for verifying whether it is implemented correctly
|
6
|
-
#
|
7
|
-
module RaiseNotImplementedError
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
class_methods do
|
10
|
-
def raise_not_implemented_error
|
11
|
-
raise_not_implemented_error_for_repository
|
12
|
-
raise_not_implemented_error_for_auth
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
# rubocop:disable Layout/LineLength
|
18
|
-
def raise_not_implemented_error_for_repository
|
19
|
-
raise NotImplementedError, "You must setting self.session_repository_class= or session_methods" unless @session_repository_class
|
20
|
-
raise NotImplementedError, "You must implement #{@session_repository_class}#find" unless @session_repository_class.method_defined? :find
|
21
|
-
raise NotImplementedError, "You must implement #{@session_repository_class}#destroy" unless @session_repository_class.method_defined? :destroy
|
22
|
-
raise NotImplementedError, "You must implement #{@session_repository_class}#destroy" unless @session_repository_class.method_defined? :destroy
|
23
|
-
raise NotImplementedError, "You must implement #{@session_repository_class}#create" unless @session_repository_class.method_defined? :create
|
24
|
-
end
|
25
|
-
# rubocop:enable Layout/LineLength
|
26
|
-
|
27
|
-
# rubocop:disable Layout/LineLength
|
28
|
-
def raise_not_implemented_error_for_auth
|
29
|
-
raise NotImplementedError, "You must setting self.auth_class= or auth_methods" unless @auth_class
|
30
|
-
raise NotImplementedError, "You must implement #{@auth_class}#find_or_create_by_auth" unless @auth_class.method_defined? :find_or_create_by_auth
|
31
|
-
raise NotImplementedError, "You must implement #{@auth_class}#update" unless @auth_class.method_defined? :update
|
32
|
-
end
|
33
|
-
# rubocop:enable Layout/LineLength
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|