trackstamps-reborn 0.0.4 → 0.0.6

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: 5d4a0992b729ef34a241b1db94c19f531768b87742137ed0d11559009f866d31
4
- data.tar.gz: a4a67c82bce9c0700d3bf33acaa85f57883a32dc78f0598decd7791ea41d6fec
3
+ metadata.gz: b0065ff981c378527149acec1b53d95da8b7e610eb8b287ec6790bfc0bb5ea81
4
+ data.tar.gz: f8a7d5a735e0b762a2849db99a3a1813a41271c58117ff0e042eed3f2b108464
5
5
  SHA512:
6
- metadata.gz: 7ce723ac73cf730e8a24a535a0ea7a6b7546e5586959500896aee8d05fdbe6d077f15e3fd0e026e4786a562fee713920fe8e13d63df7c8611da17c65ade52afc
7
- data.tar.gz: 7152a2a596e88ee180821f278cbb7407e9db282374bdb8bc2690087223c9139afc3eef6be333b237c6ed531eecff7a3846b0eb693dac9e8ed0462541c900550e
6
+ metadata.gz: f36e7eac525531cd7394a8660f862a4e736716c261cef300b46f8fc375c869bec9dc48ea0e3762751a2f280fd0ba205317c74c8ebda0284c2714a0b4b41bc5a4
7
+ data.tar.gz: 36e0e39cfc2dee3ce019682e8b759bd91cb2ba35fc492205cd7c5b3b9ed6082b64ce9173470540a3ce426103c8f8308dcfb12bc6c7d486c84cf0f7d51b3beca7
data/README.md CHANGED
@@ -37,15 +37,7 @@ end
37
37
  ### Override implementation for current user
38
38
 
39
39
  ```ruby
40
- module TrackstampsOverride
41
-
42
- extend ActiveSupport::Concern
43
- include Trackstamps::Reborn
44
-
45
- def trackstamps_current_user
46
- User.last
47
- end
48
- end
40
+ Trackstamps::Reborn.config.get_current_user = -> { YourCurrentAttributesClass.account }
49
41
  ```
50
42
 
51
43
  ### Generate migrations
@@ -1,5 +1,5 @@
1
1
  module Trackstamps
2
2
  module Reborn
3
- VERSION = "0.0.4".freeze
3
+ VERSION = "0.0.6".freeze
4
4
  end
5
5
  end
@@ -1,35 +1,53 @@
1
1
  require 'trackstamps/reborn/current'
2
2
  require 'active_support/current_attributes'
3
3
  require 'active_support/concern'
4
+ require 'dry-configurable'
4
5
 
5
6
  module Trackstamps
6
7
  module Reborn
8
+ extend Dry::Configurable
7
9
  extend ActiveSupport::Concern
8
10
  autoload :VERSION, "trackstamps/reborn/version"
9
11
 
12
+ setting :get_current_user, default: -> { Trackstamps::Reborn::Current.user }
13
+
14
+ setting :user_class_name, default: 'User'.freeze
15
+ setting :updater_foreign_key, default: 'updated_by_id'.freeze
16
+ setting :creator_foreign_key, default: 'created_by_id'.freeze
17
+
10
18
  def trackstamps_current_user
11
- Current.user
19
+ Trackstamps::Reborn.config.get_current_user.call
12
20
  end
13
21
 
14
- TRACKSTAMPS_USER_CLASS_NAME = 'User'
15
- TRACKSTAMPS_UPDATER_FOREIGN_KEY = 'updated_by_id'
16
- TRACKSTAMPS_CREATOR_FOREIGN_KEY = 'created_by_id'
17
-
18
22
  included do
19
23
  before_save :trackstamps_set_updater
20
24
  before_create :trackstamps_set_creator
21
25
 
22
- belongs_to :updater, class_name: TRACKSTAMPS_USER_CLASS_NAME, foreign_key: TRACKSTAMPS_UPDATER_FOREIGN_KEY, optional: true
23
- belongs_to :creator, class_name: TRACKSTAMPS_USER_CLASS_NAME, foreign_key: TRACKSTAMPS_CREATOR_FOREIGN_KEY, optional: true
26
+ belongs_to :updater,
27
+ class_name: Trackstamps::Reborn.config.user_class_name,
28
+ foreign_key: Trackstamps::Reborn.config.updater_foreign_key,
29
+ optional: true
30
+ belongs_to :creator,
31
+ class_name: Trackstamps::Reborn.config.user_class_name,
32
+ foreign_key: Trackstamps::Reborn.config.creator_foreign_key,
33
+ optional: true
24
34
 
25
35
  def trackstamps_set_updater
26
36
  return unless trackstamps_current_user
27
- self.send("#{TRACKSTAMPS_UPDATER_FOREIGN_KEY}=", trackstamps_current_user.id)
37
+
38
+ send("#{Trackstamps::Reborn.config.updater_foreign_key}=", trackstamps_current_user.id)
28
39
  end
29
40
 
30
41
  def trackstamps_set_creator
31
42
  return unless trackstamps_current_user
32
- self.send("#{TRACKSTAMPS_CREATOR_FOREIGN_KEY}=", trackstamps_current_user.id)
43
+
44
+ send("#{Trackstamps::Reborn.config.creator_foreign_key}=", trackstamps_current_user.id)
45
+ end
46
+ end
47
+
48
+ class_methods do
49
+ def with_trackstamps
50
+ includes(:creator, :updater)
33
51
  end
34
52
  end
35
53
  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.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dušan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-17 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
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: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
33
47
  description:
34
48
  email:
35
49
  - dusan.uveric@mitigate.dev
@@ -61,14 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
75
  requirements:
62
76
  - - ">="
63
77
  - !ruby/object:Gem::Version
64
- version: '2.6'
78
+ version: 2.7.0
65
79
  required_rubygems_version: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - ">="
68
82
  - !ruby/object:Gem::Version
69
83
  version: '0'
70
84
  requirements: []
71
- rubygems_version: 3.3.7
85
+ rubygems_version: 3.3.23
72
86
  signing_key:
73
87
  specification_version: 4
74
88
  summary: ''