trackstamps-reborn 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackstamps/base.rb +68 -49
- data/lib/trackstamps/reborn.rb +0 -5
- data/lib/trackstamps/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd2b68b118dba98cdff561775667db2e1091429b44a412e4205746fc8ba69b3
|
4
|
+
data.tar.gz: bacc74efbb46c07174eb2bd854d7f33e0c437bd9491b79146878dc082f5ec36d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bb48156152409fd08b14d69e653843873c5e02decfe0c41999587294d3e71c6ec62dbdec492a1e52bb710352a08bc1875255d409477f75dc0a3c33b51a66601
|
7
|
+
data.tar.gz: f4573930bbbc22e8b02962a00549203ce0e17eb96717acb52f1f4dd92c5a558c38d3749220d2bbd9262eee23c7c2ffb5844fcca048d09f5b50a313b2a2ddbb4a
|
data/lib/trackstamps/base.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "dry-configurable"
|
3
3
|
|
4
|
-
# rubocop:disable
|
4
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength
|
5
5
|
module Trackstamps
|
6
6
|
module Base
|
7
7
|
@mixins = ::Concurrent::Map.new
|
@@ -10,75 +10,94 @@ module Trackstamps
|
|
10
10
|
attribute :user
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.[](
|
14
|
-
@mixins.fetch_or_store(
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def self.[](module_key=:default)
|
14
|
+
@mixins.fetch_or_store(module_key.to_s) do
|
15
|
+
construct_new_module(module_key)
|
16
|
+
end
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def self.construct_new_module(module_key)
|
20
|
+
mod = Module.new
|
21
|
+
mod.define_singleton_method(:inspect) do
|
22
|
+
"Trackstamps::Reborn[:#{module_key}]"
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
mod.define_method(:trackstamps_module) do
|
26
|
+
mod
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
mod.define_singleton_method(:[]) do |key|
|
30
|
+
Trackstamps::Base[key]
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
mod.module_eval do
|
34
|
+
extend Dry::Configurable
|
35
|
+
extend ActiveSupport::Concern
|
36
|
+
autoload :VERSION, "trackstamps/reborn/version"
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
const_set(:Current, Trackstamps::Base::Current)
|
39
|
+
|
40
|
+
setting :get_current_user, default: -> { Current.user }
|
41
|
+
setting :user_class_name, default: "User".freeze
|
42
|
+
setting :updater_foreign_key, default: "updated_by_id".freeze
|
43
|
+
setting :creator_foreign_key, default: "created_by_id".freeze
|
44
|
+
|
45
|
+
included do
|
46
|
+
def trackstamps_current_user
|
47
|
+
trackstamps_module.config.get_current_user.call
|
35
48
|
end
|
36
49
|
|
37
|
-
|
38
|
-
|
39
|
-
base.class_eval do
|
40
|
-
before_save :trackstamps_set_updater
|
41
|
-
before_create :trackstamps_set_creator
|
50
|
+
private :trackstamps_module
|
51
|
+
private :trackstamps_current_user
|
42
52
|
|
43
|
-
|
53
|
+
before_save :trackstamps_set_updater
|
54
|
+
before_create :trackstamps_set_creator
|
44
55
|
|
45
|
-
|
56
|
+
const_set(
|
57
|
+
:UPDATER_FOREIGN_KEY,
|
58
|
+
mod.config.updater_foreign_key.dup.freeze
|
59
|
+
)
|
60
|
+
const_set(
|
61
|
+
:CREATOR_FOREIGN_KEY,
|
62
|
+
mod.config.creator_foreign_key.dup.freeze
|
63
|
+
)
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
foreign_key: const_get(:UPDATER_FOREIGN_KEY),
|
50
|
-
optional: true
|
65
|
+
private_constant :UPDATER_FOREIGN_KEY
|
66
|
+
private_constant :CREATOR_FOREIGN_KEY
|
51
67
|
|
52
|
-
|
53
|
-
|
68
|
+
belongs_to :updater,
|
69
|
+
class_name: mod.config.user_class_name,
|
70
|
+
foreign_key: const_get(:UPDATER_FOREIGN_KEY),
|
71
|
+
optional: true
|
54
72
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
73
|
+
belongs_to :creator,
|
74
|
+
class_name: mod.config.user_class_name,
|
75
|
+
foreign_key: const_get(:CREATOR_FOREIGN_KEY),
|
76
|
+
optional: true
|
59
77
|
|
60
|
-
|
61
|
-
|
78
|
+
def trackstamps_set_updater
|
79
|
+
return unless trackstamps_current_user
|
62
80
|
|
63
|
-
|
64
|
-
|
81
|
+
send(:"#{self.class.const_get(:UPDATER_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
82
|
+
end
|
65
83
|
|
66
|
-
|
67
|
-
|
84
|
+
def trackstamps_set_creator
|
85
|
+
return unless trackstamps_current_user
|
68
86
|
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
87
|
+
send(:"#{self.class.const_get(:CREATOR_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
72
88
|
end
|
89
|
+
end
|
73
90
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
91
|
+
class_methods do
|
92
|
+
def with_trackstamps
|
93
|
+
includes(:creator, :updater)
|
78
94
|
end
|
79
95
|
end
|
80
96
|
end
|
97
|
+
|
98
|
+
mod
|
81
99
|
end
|
82
100
|
end
|
83
101
|
end
|
84
|
-
|
102
|
+
|
103
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength
|
data/lib/trackstamps/reborn.rb
CHANGED
data/lib/trackstamps/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackstamps-reborn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dušan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|