trackstamps-reborn 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fadfa370c842bc476bfa043e9fbf39403f63670a04688cfec1dbf71fa6e08aa6
4
+ data.tar.gz: 75b0cdeb8330a0532c44abc9666c2636786481934d4aba58d99784d004e99269
5
+ SHA512:
6
+ metadata.gz: 18b286fe9b6431c629ba07bd8c324ad4d8e25405968d6ee411e984a05abff1580f0e7786b1f9bc98d700f00a8e3809691c760921081ad85550640f62f28350c8
7
+ data.tar.gz: c360f942e6dafa16d5b592ddafccfe02646b24b1a0363cd0b1e320ba0d47e99872840b97508d6de6ab71d25aaca945d2d1de3d169500449dd5e0ac4d89f8127f
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Dušan
4
+ Copyright (c) 2015 Shahzad Tariq
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # trackstamps-reborn
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/trackstamps-reborn.svg)](https://rubygems.org/gems/trackstamps-reborn)
4
+ [![Circle](https://circleci.com/gh/uvera/trackstamps-reborn/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/uvera/trackstamps-reborn?branch=main)
5
+ [![Code Climate](https://codeclimate.com/github/uvera/trackstamps-reborn/badges/gpa.svg)](https://codeclimate.com/github/uvera/trackstamps-reborn)
6
+
7
+ Track which user created or updated record in Rails.
8
+
9
+ ---
10
+
11
+ - [Quick start](#quick-start)
12
+ - [Support](#support)
13
+ - [License](#license)
14
+ - [Code of conduct](#code-of-conduct)
15
+ - [Contribution guide](#contribution-guide)
16
+
17
+ ## Quick start
18
+
19
+ ```
20
+ $ bundler install trackstamps-reborn
21
+ ```
22
+
23
+ ### Hook current_user into CurrentAttributes
24
+
25
+ ```ruby
26
+ class ApplicationController < ActionController::Base
27
+ before_action :set_trackstamps_user
28
+
29
+ def set_trackstamps_user
30
+ Trackstamps::Reborn::Current.user = current_user
31
+ end
32
+ end
33
+ ```
34
+
35
+ ### Generate migrations
36
+ ```
37
+ rails generate trackstamps:reborn:migration table_name
38
+ ```
39
+
40
+ ## Include trackstamps
41
+ ```ruby
42
+ class Example < ActiveRecord::Base
43
+ include Trackstamps::Reborn
44
+ end
45
+ ```
46
+
47
+ ## Support
48
+
49
+ 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!
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
54
+
55
+ ## Code of conduct
56
+
57
+ Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
58
+
59
+ ## Contribution guide
60
+
61
+ Pull requests are welcome!
@@ -0,0 +1,29 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class Trackstamps::Reborn::MigrationGenerator < ::Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :table, :type => :string, :default => "application"
8
+ desc 'Generate migration file required for trackstamps'
9
+
10
+ def install
11
+ migration_template 'migration.rb', "db/migrate/add_trackstamps_to_#{table}.rb"
12
+ end
13
+
14
+ def migration_data
15
+ <<-RUBY
16
+ add_column :#{table}, :created_by_id, :integer
17
+ add_column :#{table}, :updated_by_id, :integer
18
+ RUBY
19
+ end
20
+
21
+ def table_name
22
+ table
23
+ end
24
+
25
+ def self.next_migration_number(dirname)
26
+ next_migration_number = current_migration_number(dirname) + 1
27
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ class AddTrackstampsTo<%= table_name.classify.pluralize -%> < ActiveRecord::Migration<%= [Rails::VERSION::STRING.to_f] if Rails::VERSION::MAJOR >= 5 -%>
2
+
3
+ def change
4
+ <%= migration_data -%>
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Trackstamps
2
+ module Reborn
3
+ class Current < ActiveSupport::CurrentAttributes
4
+ attribute :user
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Trackstamps
2
+ module Reborn
3
+ VERSION = "0.0.3".freeze
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'trackstamps/reborn/current'
2
+ require 'active_support/current_attributes'
3
+ require 'active_support/concern'
4
+
5
+ module Trackstamps
6
+ module Reborn
7
+ extend ActiveSupport::Concern
8
+ autoload :VERSION, "trackstamps/reborn/version"
9
+
10
+ def trackstamps_current_user
11
+ Current.user
12
+ end
13
+
14
+ TRACKSTAMPS_USER_CLASS_NAME = 'User'
15
+ TRACKSTAMPS_UPDATER_FOREIGN_KEY = 'updated_by_id'
16
+ TRACKSTAMPS_CREATOR_FOREIGN_KEY = 'created_by_id'
17
+
18
+ included do
19
+ before_save :trackstamps_set_updater
20
+ before_create :trackstamps_set_creator
21
+
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
24
+
25
+ def trackstamps_set_updater
26
+ return unless trackstamps_current_user
27
+ self.send("#{TRACKSTAMPS_UPDATER_FOREIGN_KEY}=", trackstamps_current_user.id)
28
+ end
29
+
30
+ def trackstamps_set_creator
31
+ return unless trackstamps_current_user
32
+ self.send("#{TRACKSTAMPS_CREATOR_FOREIGN_KEY}=", trackstamps_current_user.id)
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trackstamps-reborn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Dušan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ description:
28
+ email:
29
+ - dusan.uveric@mitigate.dev
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - README.md
36
+ - lib/generators/trackstamps/reborn/migration_generator.rb
37
+ - lib/generators/trackstamps/reborn/templates/migration.rb
38
+ - lib/trackstamps/reborn.rb
39
+ - lib/trackstamps/reborn/current.rb
40
+ - lib/trackstamps/reborn/version.rb
41
+ homepage: https://github.com/uvera/trackstamps-reborn
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ bug_tracker_uri: https://github.com/uvera/trackstamps-reborn/issues
46
+ changelog_uri: https://github.com/uvera/trackstamps-reborn/releases
47
+ source_code_uri: https://github.com/uvera/trackstamps-reborn
48
+ homepage_uri: https://github.com/uvera/trackstamps-reborn
49
+ rubygems_mfa_required: 'true'
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '2.6'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.3.7
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: ''
69
+ test_files: []