trackstamps-reborn 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/lib/generators/trackstamps/reborn/migration_generator.rb +5 -5
- data/lib/trackstamps/base.rb +84 -0
- data/lib/trackstamps/reborn.rb +5 -56
- data/lib/trackstamps/version.rb +3 -0
- metadata +21 -21
- data/lib/trackstamps/reborn/current.rb +0 -7
- data/lib/trackstamps/reborn/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f6ded086f151de9ea9948bf8ce5055bf668c8c591e4c7e745dae7461cbe438c
|
4
|
+
data.tar.gz: 4b1fd16c08d4fa1e15265f8e2ad929c5225db30e5671ff4d18ed696a9a131dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5902f55877212109239d449fb196c6fc303066b8cfa153ab20f04142885a68ada8bbb606b51ee232a38124477aac59dde7addb9ca3870faca5cbc636909d4900
|
7
|
+
data.tar.gz: 7a2b7cae52e62135381460889ecfd6147d1e84512fe7a1c0a3395fc3018a767cb67ca8e82badee7428810f48353d52d6593abb732162ea23e80d6559c473ffb2
|
data/README.md
CHANGED
@@ -29,6 +29,8 @@ class ApplicationController < ActionController::Base
|
|
29
29
|
|
30
30
|
def set_trackstamps_user
|
31
31
|
Trackstamps::Reborn::Current.user = current_user
|
32
|
+
# or use your current attributes class with proc override in initializers
|
33
|
+
YourCurrentAttributesClass.user = current_user
|
32
34
|
end
|
33
35
|
end
|
34
36
|
```
|
@@ -36,7 +38,10 @@ end
|
|
36
38
|
### Override implementation for current user
|
37
39
|
|
38
40
|
```ruby
|
39
|
-
|
41
|
+
## filename: config/initializers/trackstamps-reborn.rb
|
42
|
+
Trackstamps::Reborn.config.get_current_user = -> { YourCurrentAttributesClass.user }
|
43
|
+
# or
|
44
|
+
Trackstamps::Reborn[:alternative].config.get_current_user = -> { YourAlternativeCurrentAttributesClass.user }
|
40
45
|
```
|
41
46
|
|
42
47
|
### Generate migrations
|
@@ -48,9 +53,22 @@ rails generate trackstamps:reborn:migration table_name
|
|
48
53
|
```ruby
|
49
54
|
class Example < ActiveRecord::Base
|
50
55
|
include Trackstamps::Reborn
|
56
|
+
# or
|
57
|
+
include Trackstamps::Reborn[:whatever]
|
51
58
|
end
|
52
59
|
```
|
53
60
|
|
61
|
+
## Multiple configuration
|
62
|
+
|
63
|
+
Multiple configuration is achieved with module builder pattern utilizing `self.[]` method.
|
64
|
+
Upon calling
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Trackstamps::Reborn[:whatever]
|
68
|
+
```
|
69
|
+
|
70
|
+
specific module is cached in `::Concurrent::Map` instance.
|
71
|
+
|
54
72
|
## Support
|
55
73
|
|
56
74
|
If you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/uvera/trackstamps-reborn/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/active_record"
|
2
2
|
|
3
3
|
class Trackstamps::Reborn::MigrationGenerator < ::Rails::Generators::Base
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
|
6
|
-
source_root File.expand_path(
|
7
|
-
argument :table, :
|
8
|
-
desc
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
argument :table, type: :string, default: "application"
|
8
|
+
desc "Generate migration file required for trackstamps"
|
9
9
|
|
10
10
|
def install
|
11
|
-
migration_template
|
11
|
+
migration_template "migration.rb", "db/migrate/add_trackstamps_to_#{table}.rb"
|
12
12
|
end
|
13
13
|
|
14
14
|
def migration_data
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "dry-configurable"
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength, Style/ClassVars
|
5
|
+
module Trackstamps
|
6
|
+
module Base
|
7
|
+
@mixins = ::Concurrent::Map.new
|
8
|
+
|
9
|
+
class Current < ::ActiveSupport::CurrentAttributes
|
10
|
+
attribute :user
|
11
|
+
end
|
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)
|
18
|
+
|
19
|
+
extend Dry::Configurable
|
20
|
+
extend ActiveSupport::Concern
|
21
|
+
autoload :VERSION, "trackstamps/reborn/version"
|
22
|
+
|
23
|
+
setting :get_current_user, default: -> { Current.user }
|
24
|
+
|
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
|
28
|
+
|
29
|
+
def trackstamps_current_user
|
30
|
+
Trackstamps::Base[@@trackstamps_target_key].config.get_current_user.call
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.inspect
|
34
|
+
"Trackstamps::Reborn[:#{@@trackstamps_target_key}]"
|
35
|
+
end
|
36
|
+
|
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
|
42
|
+
|
43
|
+
const_set(:UPDATER_FOREIGN_KEY, trackstamps_module_self.config.updater_foreign_key.dup.freeze)
|
44
|
+
|
45
|
+
private_constant :UPDATER_FOREIGN_KEY
|
46
|
+
|
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
|
51
|
+
|
52
|
+
const_set(:CREATOR_FOREIGN_KEY, trackstamps_module_self.config.creator_foreign_key.dup.freeze)
|
53
|
+
private_constant :CREATOR_FOREIGN_KEY
|
54
|
+
|
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
|
59
|
+
|
60
|
+
def trackstamps_set_updater
|
61
|
+
return unless trackstamps_current_user
|
62
|
+
|
63
|
+
send(:"#{self.class.const_get(:UPDATER_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def trackstamps_set_creator
|
67
|
+
return unless trackstamps_current_user
|
68
|
+
|
69
|
+
send(:"#{self.class.const_get(:CREATOR_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class_methods do
|
75
|
+
def with_trackstamps
|
76
|
+
includes(:creator, :updater)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength, Style/ClassVars
|
data/lib/trackstamps/reborn.rb
CHANGED
@@ -1,61 +1,10 @@
|
|
1
|
-
|
2
|
-
require "trackstamps/reborn/current"
|
3
|
-
require "dry-configurable"
|
1
|
+
require_relative "base"
|
4
2
|
|
5
3
|
module Trackstamps
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
setting :get_current_user, default: -> { Trackstamps::Reborn::Current.user }
|
12
|
-
|
13
|
-
setting :user_class_name, default: "User".freeze
|
14
|
-
setting :updater_foreign_key, default: "updated_by_id".freeze
|
15
|
-
setting :creator_foreign_key, default: "created_by_id".freeze
|
16
|
-
|
17
|
-
def trackstamps_current_user
|
18
|
-
Trackstamps::Reborn.config.get_current_user.call
|
19
|
-
end
|
20
|
-
|
21
|
-
included do
|
22
|
-
before_save :trackstamps_set_updater
|
23
|
-
before_create :trackstamps_set_creator
|
24
|
-
|
25
|
-
const_set(:UPDATER_FOREIGN_KEY, Trackstamps::Reborn.config.updater_foreign_key.dup.freeze)
|
26
|
-
|
27
|
-
private_constant :UPDATER_FOREIGN_KEY
|
28
|
-
|
29
|
-
belongs_to :updater,
|
30
|
-
class_name: Trackstamps::Reborn.config.user_class_name,
|
31
|
-
foreign_key: const_get(:UPDATER_FOREIGN_KEY),
|
32
|
-
optional: true
|
33
|
-
|
34
|
-
const_set(:CREATOR_FOREIGN_KEY, Trackstamps::Reborn.config.creator_foreign_key.dup.freeze)
|
35
|
-
private_constant :CREATOR_FOREIGN_KEY
|
36
|
-
|
37
|
-
belongs_to :creator,
|
38
|
-
class_name: Trackstamps::Reborn.config.user_class_name,
|
39
|
-
foreign_key: const_get(:CREATOR_FOREIGN_KEY),
|
40
|
-
optional: true
|
41
|
-
|
42
|
-
def trackstamps_set_updater
|
43
|
-
return unless trackstamps_current_user
|
44
|
-
|
45
|
-
send("#{self.class.const_get(:UPDATER_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
46
|
-
end
|
47
|
-
|
48
|
-
def trackstamps_set_creator
|
49
|
-
return unless trackstamps_current_user
|
50
|
-
|
51
|
-
send("#{self.class.const_get(:CREATOR_FOREIGN_KEY)}=", trackstamps_current_user.id)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class_methods do
|
56
|
-
def with_trackstamps
|
57
|
-
includes(:creator, :updater)
|
58
|
-
end
|
4
|
+
Reborn = Trackstamps::Base[:default]
|
5
|
+
Reborn.module_eval do
|
6
|
+
def self.[](instance_name)
|
7
|
+
Trackstamps::Base[instance_name]
|
59
8
|
end
|
60
9
|
end
|
61
10
|
end
|
metadata
CHANGED
@@ -1,31 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackstamps-reborn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2024-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rails
|
14
|
+
name: activesupport
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
@@ -44,9 +30,23 @@ dependencies:
|
|
44
30
|
- - "<"
|
45
31
|
- !ruby/object:Gem::Version
|
46
32
|
version: '8'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dry-configurable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
47
|
description:
|
48
48
|
email:
|
49
|
-
-
|
49
|
+
- dusanuveric@protonmail.com
|
50
50
|
executables: []
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
@@ -55,9 +55,9 @@ files:
|
|
55
55
|
- README.md
|
56
56
|
- lib/generators/trackstamps/reborn/migration_generator.rb
|
57
57
|
- lib/generators/trackstamps/reborn/templates/migration.rb
|
58
|
+
- lib/trackstamps/base.rb
|
58
59
|
- lib/trackstamps/reborn.rb
|
59
|
-
- lib/trackstamps/
|
60
|
-
- lib/trackstamps/reborn/version.rb
|
60
|
+
- lib/trackstamps/version.rb
|
61
61
|
homepage: https://github.com/uvera/trackstamps-reborn
|
62
62
|
licenses:
|
63
63
|
- MIT
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.5.11
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: ''
|