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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f6ded086f151de9ea9948bf8ce5055bf668c8c591e4c7e745dae7461cbe438c
4
- data.tar.gz: 4b1fd16c08d4fa1e15265f8e2ad929c5225db30e5671ff4d18ed696a9a131dcb
3
+ metadata.gz: 6bd2b68b118dba98cdff561775667db2e1091429b44a412e4205746fc8ba69b3
4
+ data.tar.gz: bacc74efbb46c07174eb2bd854d7f33e0c437bd9491b79146878dc082f5ec36d
5
5
  SHA512:
6
- metadata.gz: 5902f55877212109239d449fb196c6fc303066b8cfa153ab20f04142885a68ada8bbb606b51ee232a38124477aac59dde7addb9ca3870faca5cbc636909d4900
7
- data.tar.gz: 7a2b7cae52e62135381460889ecfd6147d1e84512fe7a1c0a3395fc3018a767cb67ca8e82badee7428810f48353d52d6593abb732162ea23e80d6559c473ffb2
6
+ metadata.gz: 6bb48156152409fd08b14d69e653843873c5e02decfe0c41999587294d3e71c6ec62dbdec492a1e52bb710352a08bc1875255d409477f75dc0a3c33b51a66601
7
+ data.tar.gz: f4573930bbbc22e8b02962a00549203ce0e17eb96717acb52f1f4dd92c5a558c38d3749220d2bbd9262eee23c7c2ffb5844fcca048d09f5b50a313b2a2ddbb4a
@@ -1,7 +1,7 @@
1
1
  require "active_support"
2
2
  require "dry-configurable"
3
3
 
4
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength, Style/ClassVars
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.[](instance_name=:default)
14
- @mixins.fetch_or_store(instance_name.to_s) do
15
- Module.new do
16
- @@trackstamps_target_key = instance_name
17
- const_set(:Current, Trackstamps::Base::Current)
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
- extend Dry::Configurable
20
- extend ActiveSupport::Concern
21
- autoload :VERSION, "trackstamps/reborn/version"
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
- setting :get_current_user, default: -> { Current.user }
25
+ mod.define_method(:trackstamps_module) do
26
+ mod
27
+ end
24
28
 
25
- setting :user_class_name, default: "User".freeze
26
- setting :updater_foreign_key, default: "updated_by_id".freeze
27
- setting :creator_foreign_key, default: "created_by_id".freeze
29
+ mod.define_singleton_method(:[]) do |key|
30
+ Trackstamps::Base[key]
31
+ end
28
32
 
29
- def trackstamps_current_user
30
- Trackstamps::Base[@@trackstamps_target_key].config.get_current_user.call
31
- end
33
+ mod.module_eval do
34
+ extend Dry::Configurable
35
+ extend ActiveSupport::Concern
36
+ autoload :VERSION, "trackstamps/reborn/version"
32
37
 
33
- def self.inspect
34
- "Trackstamps::Reborn[:#{@@trackstamps_target_key}]"
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
- def self.included(base)
38
- trackstamps_module_self = self
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
- const_set(:UPDATER_FOREIGN_KEY, trackstamps_module_self.config.updater_foreign_key.dup.freeze)
53
+ before_save :trackstamps_set_updater
54
+ before_create :trackstamps_set_creator
44
55
 
45
- private_constant :UPDATER_FOREIGN_KEY
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
- belongs_to :updater,
48
- class_name: trackstamps_module_self.config.user_class_name,
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
- const_set(:CREATOR_FOREIGN_KEY, trackstamps_module_self.config.creator_foreign_key.dup.freeze)
53
- private_constant :CREATOR_FOREIGN_KEY
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
- belongs_to :creator,
56
- class_name: trackstamps_module_self.config.user_class_name,
57
- foreign_key: const_get(:CREATOR_FOREIGN_KEY),
58
- optional: true
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
- def trackstamps_set_updater
61
- return unless trackstamps_current_user
78
+ def trackstamps_set_updater
79
+ return unless trackstamps_current_user
62
80
 
63
- send(:"#{self.class.const_get(:UPDATER_FOREIGN_KEY)}=", trackstamps_current_user.id)
64
- end
81
+ send(:"#{self.class.const_get(:UPDATER_FOREIGN_KEY)}=", trackstamps_current_user.id)
82
+ end
65
83
 
66
- def trackstamps_set_creator
67
- return unless trackstamps_current_user
84
+ def trackstamps_set_creator
85
+ return unless trackstamps_current_user
68
86
 
69
- send(:"#{self.class.const_get(:CREATOR_FOREIGN_KEY)}=", trackstamps_current_user.id)
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
- class_methods do
75
- def with_trackstamps
76
- includes(:creator, :updater)
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
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength, Style/ClassVars
102
+
103
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength
@@ -2,9 +2,4 @@ require_relative "base"
2
2
 
3
3
  module Trackstamps
4
4
  Reborn = Trackstamps::Base[:default]
5
- Reborn.module_eval do
6
- def self.[](instance_name)
7
- Trackstamps::Base[instance_name]
8
- end
9
- end
10
5
  end
@@ -1,3 +1,3 @@
1
1
  module Trackstamps
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.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-08-25 00:00:00.000000000 Z
11
+ date: 2024-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport