current_session 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +12 -0
- data/Gemfile.lock +16 -16
- data/current_session.gemspec +1 -2
- data/lib/current_session/base.rb +18 -4
- data/lib/current_session/session_methods/active_record_session.rb +35 -0
- data/lib/current_session/session_methods/env_session.rb +32 -0
- data/lib/current_session/session_methods/uid_session.rb +21 -0
- data/lib/current_session/session_methods.rb +13 -0
- data/lib/current_session/version.rb +1 -1
- data/lib/current_session.rb +4 -4
- metadata +9 -7
- data/lib/current_session/active_record_session.rb +0 -33
- data/lib/current_session/env_session.rb +0 -30
- data/lib/current_session/uid_session.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b39dda8338daaeb45ccebe39f01c23931d9387685619750a65c0a1acc7f6cb
|
4
|
+
data.tar.gz: 8214ca0c3d15c9d8cb27a963ba41e5e7cd71375c1e2d24ea616972b3beeed193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e1e74c3e85d3806e3d8235f396f67d5132a7ff3ba49bd384d3a0bb316073ec9d17bf3f546a92754c0beceb43b08740532ec75a4a25a32c8cc9f835fcec29f7f
|
7
|
+
data.tar.gz: 3c0f7bba4344ab4be82509930173accd0b76712ee07b3dbb8018f788a22304d467c27478aa9ca7691ebecb794f7783cf835cecf8b9ed90f6bcdb005cc8e2df2e
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-rspec
|
6
|
+
|
1
7
|
AllCops:
|
2
8
|
TargetRubyVersion: 3.0
|
3
9
|
NewCops: enable
|
@@ -23,3 +29,6 @@ Style/EmptyMethod:
|
|
23
29
|
|
24
30
|
Lint/EmptyBlock:
|
25
31
|
Enabled: false
|
32
|
+
|
33
|
+
RSpec/MultipleExpectations:
|
34
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-09-06 00:54:54 UTC using RuboCop version 1.36.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 10
|
10
|
+
# Configuration parameters: AllowSubject.
|
11
|
+
RSpec/MultipleMemoizedHelpers:
|
12
|
+
Max: 9
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
current_session (0.1.
|
5
|
-
activesupport
|
4
|
+
current_session (0.1.3)
|
5
|
+
activesupport (>= 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (7.0.
|
11
|
-
activesupport (= 7.0.
|
12
|
-
activerecord (7.0.
|
13
|
-
activemodel (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
15
|
-
activesupport (7.0.
|
10
|
+
activemodel (7.0.4)
|
11
|
+
activesupport (= 7.0.4)
|
12
|
+
activerecord (7.0.4)
|
13
|
+
activemodel (= 7.0.4)
|
14
|
+
activesupport (= 7.0.4)
|
15
|
+
activesupport (7.0.4)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
@@ -39,12 +39,12 @@ GEM
|
|
39
39
|
pry (0.14.1)
|
40
40
|
coderay (~> 1.1)
|
41
41
|
method_source (~> 1.0)
|
42
|
-
rack (
|
43
|
-
rack-protection (
|
42
|
+
rack (3.0.0)
|
43
|
+
rack-protection (3.0.1)
|
44
44
|
rack
|
45
45
|
rainbow (3.1.1)
|
46
46
|
rake (13.0.6)
|
47
|
-
regexp_parser (2.
|
47
|
+
regexp_parser (2.6.0)
|
48
48
|
rexml (3.2.5)
|
49
49
|
rspec (3.11.0)
|
50
50
|
rspec-core (~> 3.11.0)
|
@@ -52,14 +52,14 @@ GEM
|
|
52
52
|
rspec-mocks (~> 3.11.0)
|
53
53
|
rspec-core (3.11.0)
|
54
54
|
rspec-support (~> 3.11.0)
|
55
|
-
rspec-expectations (3.11.
|
55
|
+
rspec-expectations (3.11.1)
|
56
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
57
|
rspec-support (~> 3.11.0)
|
58
58
|
rspec-mocks (3.11.1)
|
59
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
60
|
rspec-support (~> 3.11.0)
|
61
|
-
rspec-support (3.11.
|
62
|
-
rubocop (1.
|
61
|
+
rspec-support (3.11.1)
|
62
|
+
rubocop (1.36.0)
|
63
63
|
json (~> 2.3)
|
64
64
|
parallel (~> 1.10)
|
65
65
|
parser (>= 3.1.2.1)
|
@@ -78,10 +78,10 @@ GEM
|
|
78
78
|
simplecov_json_formatter (~> 0.1)
|
79
79
|
simplecov-html (0.12.3)
|
80
80
|
simplecov_json_formatter (0.1.4)
|
81
|
-
sqlite3 (1.
|
81
|
+
sqlite3 (1.5.1-arm64-darwin)
|
82
82
|
tzinfo (2.0.5)
|
83
83
|
concurrent-ruby (~> 1.0)
|
84
|
-
unicode-display_width (2.
|
84
|
+
unicode-display_width (2.3.0)
|
85
85
|
|
86
86
|
PLATFORMS
|
87
87
|
arm64-darwin-20
|
data/current_session.gemspec
CHANGED
@@ -27,8 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
-
|
31
|
-
spec.add_runtime_dependency "activesupport"
|
30
|
+
spec.add_runtime_dependency "activesupport", ">= 6.0.0"
|
32
31
|
|
33
32
|
# For more information and examples about making a new gem, checkout our
|
34
33
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/current_session/base.rb
CHANGED
@@ -16,16 +16,30 @@ module CurrentSession
|
|
16
16
|
Time.current
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@session_repository_class =
|
19
|
+
def session_methods=(session_methods_module)
|
20
|
+
@session_repository_class = Class.new(CurrentSession::Repository) { include session_methods_module }
|
21
21
|
end
|
22
22
|
|
23
23
|
def session_methods(&block)
|
24
|
-
|
24
|
+
if block
|
25
|
+
session_methods = Module.new(&block)
|
26
|
+
@session_repository_class = Class.new(CurrentSession::Repository) { include session_methods }
|
27
|
+
else
|
28
|
+
@session_repository_class
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def auth_methods=(auth_methods_module)
|
33
|
+
@auth_class = Class.new(CurrentSession::Auth) { include auth_methods_module }
|
25
34
|
end
|
26
35
|
|
27
36
|
def auth_methods(&block)
|
28
|
-
|
37
|
+
if block
|
38
|
+
auth_methods = Module.new(&block)
|
39
|
+
@auth_class = Class.new(CurrentSession::Auth) { include auth_methods }
|
40
|
+
else
|
41
|
+
@auth_class
|
42
|
+
end
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CurrentSession
|
4
|
+
module SessionMethods
|
5
|
+
#
|
6
|
+
# Implementation of session tokens for DB management
|
7
|
+
#
|
8
|
+
module ActiveRecordSession
|
9
|
+
def find
|
10
|
+
session_token_class.find_by(value: session_token).try do |record|
|
11
|
+
update(record)
|
12
|
+
yield record.user
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(user)
|
17
|
+
session_token_class.create(user_id: user.id, value: new_session_token) do |record|
|
18
|
+
update(record)
|
19
|
+
end.value
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(token)
|
23
|
+
token.update(
|
24
|
+
last_request_at: current_time,
|
25
|
+
last_request_ip: request.remote_ip,
|
26
|
+
last_request_user_agent: request.user_agent
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
session_token_class.find_by(value: session_token)&.destroy
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CurrentSession
|
4
|
+
module SessionMethods
|
5
|
+
#
|
6
|
+
# repository to return the user specified by the environment variable
|
7
|
+
#
|
8
|
+
module EnvSession
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
10
|
+
def self.build(current_user_id)
|
11
|
+
Module.new do
|
12
|
+
define_method(:current_user) { user_class.find(current_user_id) }
|
13
|
+
|
14
|
+
def try
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
|
18
|
+
def find
|
19
|
+
yield current_user
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(_)
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
# rubocop:enable Metrics/MethodLength
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CurrentSession
|
4
|
+
module SessionMethods
|
5
|
+
#
|
6
|
+
# Implementation of using UIDs as session tokens
|
7
|
+
#
|
8
|
+
module UidSession
|
9
|
+
def find(&block)
|
10
|
+
user_class.find_by(uid: session_token).try(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(user)
|
14
|
+
user.uid
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Reference implementation of session_methods
|
5
|
+
#
|
6
|
+
module CurrentSession
|
7
|
+
module SessionMethods
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
autoload :UidSession
|
10
|
+
autoload :EnvSession
|
11
|
+
autoload :ActiveRecordSession
|
12
|
+
end
|
13
|
+
end
|
data/lib/current_session.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require_relative "current_session/version"
|
4
4
|
require "active_support"
|
5
5
|
|
6
|
+
#
|
7
|
+
# current_session
|
8
|
+
#
|
6
9
|
module CurrentSession
|
7
10
|
extend ActiveSupport::Autoload
|
8
11
|
autoload :Base
|
@@ -10,10 +13,7 @@ module CurrentSession
|
|
10
13
|
autoload :Auth
|
11
14
|
autoload :Repository
|
12
15
|
autoload :RaiseNotImplementedError
|
13
|
-
|
14
|
-
autoload :UidSession
|
15
|
-
autoload :EnvSession
|
16
|
-
autoload :ActiveRecordSession
|
16
|
+
autoload :SessionMethods
|
17
17
|
|
18
18
|
def self.key(user_class)
|
19
19
|
"session_#{user_class.name.underscore.parameterize(separator: "_")}_key"
|
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.3
|
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-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- ".gitignore"
|
135
135
|
- ".rspec"
|
136
136
|
- ".rubocop.yml"
|
137
|
+
- ".rubocop_todo.yml"
|
137
138
|
- CHANGELOG.md
|
138
139
|
- CODE_OF_CONDUCT.md
|
139
140
|
- Gemfile
|
@@ -145,14 +146,15 @@ files:
|
|
145
146
|
- bin/setup
|
146
147
|
- current_session.gemspec
|
147
148
|
- lib/current_session.rb
|
148
|
-
- lib/current_session/active_record_session.rb
|
149
149
|
- lib/current_session/auth.rb
|
150
150
|
- lib/current_session/base.rb
|
151
|
-
- lib/current_session/env_session.rb
|
152
151
|
- lib/current_session/interface.rb
|
153
152
|
- lib/current_session/raise_not_implemented_error.rb
|
154
153
|
- lib/current_session/repository.rb
|
155
|
-
- lib/current_session/
|
154
|
+
- lib/current_session/session_methods.rb
|
155
|
+
- lib/current_session/session_methods/active_record_session.rb
|
156
|
+
- lib/current_session/session_methods/env_session.rb
|
157
|
+
- lib/current_session/session_methods/uid_session.rb
|
156
158
|
- lib/current_session/version.rb
|
157
159
|
homepage: https://github.com/aileron-inc/current_session
|
158
160
|
licenses:
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
#
|
5
|
-
# Implementation of session tokens for DB management
|
6
|
-
#
|
7
|
-
class ActiveRecordSession < Repository
|
8
|
-
def find
|
9
|
-
session_token_class.find_by(value: session_token).try do |record|
|
10
|
-
update(record)
|
11
|
-
yield record.user
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def create(user)
|
16
|
-
session_token_class.create(user_id: user.id, value: new_session_token) do |record|
|
17
|
-
update(record)
|
18
|
-
end.value
|
19
|
-
end
|
20
|
-
|
21
|
-
def update(token)
|
22
|
-
token.update(
|
23
|
-
last_request_at: current_time,
|
24
|
-
last_request_ip: request.remote_ip,
|
25
|
-
last_request_user_agent: request.user_agent
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
def destroy
|
30
|
-
session_token_class.find_by(value: session_token)&.destroy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
#
|
5
|
-
# repository to return the user specified by the environment variable
|
6
|
-
#
|
7
|
-
class EnvSession < Repository
|
8
|
-
# rubocop:disable Metrics/MethodLength
|
9
|
-
def self.build(current_user_id)
|
10
|
-
Class.new(Repository) do
|
11
|
-
define_method(:current_user) { user_class.find(current_user_id) }
|
12
|
-
|
13
|
-
def try
|
14
|
-
yield self
|
15
|
-
end
|
16
|
-
|
17
|
-
def find
|
18
|
-
yield current_user
|
19
|
-
end
|
20
|
-
|
21
|
-
def create(_)
|
22
|
-
end
|
23
|
-
|
24
|
-
def destroy
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
# rubocop:enable Metrics/MethodLength
|
29
|
-
end
|
30
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
#
|
5
|
-
# Implementation of using UIDs as session tokens
|
6
|
-
#
|
7
|
-
class UidSession < Repository
|
8
|
-
def find(&block)
|
9
|
-
user_class.find_by(uid: session_token).try(&block)
|
10
|
-
end
|
11
|
-
|
12
|
-
def create(user)
|
13
|
-
user.uid
|
14
|
-
end
|
15
|
-
|
16
|
-
def destroy
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|