paper_trail-globalid 0.1.2.rc
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 +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/lib/paper_trail_globalid.rb +15 -0
- data/lib/paper_trail_globalid/paper_trail.rb +21 -0
- data/lib/paper_trail_globalid/version.rb +3 -0
- data/lib/paper_trail_globalid/version_concern.rb +19 -0
- data/paper_trail_globalid.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 05709a7d0e45d43c43bcbaf60181092ffb82440b
|
|
4
|
+
data.tar.gz: b76c015d28a0062793052dc2eb7311f7881f62cd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c2a6cb1fe2a3e1f95d4c0fbd1c88d4280c694deed699adf5aabbb98567b5b199d7040eb977fb4163eb8fabbe1bcf77d7186318d09c858461a6b992a994efdec4
|
|
7
|
+
data.tar.gz: 94865f8f943b5b7f49deef53fd7c57615df47e90171fd5491b1d3664db780a31c4fea781e143ef1a5c76545f708d502b1995c2f97d8706d693faf898514c356d
|
data/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
|
23
|
+
.DS_Store
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2016 ankit1910
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# PaperTrailGlobalid
|
|
2
|
+
This gem is an extension to paper_trail gem https://github.com/airblade/paper_trail. That means you need to pre install `paper_trail` gem. This gem will add one more method `actor` to instances of `PaperTrail::Version` that will return you the `ActiveRecord` object who was responsible for change.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Supported Rails
|
|
6
|
+
|
|
7
|
+
This Gem only support `>= rails 4.1.0` and above versions.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
1. Add PaperTrailGlobalid to your `Gemfile`.
|
|
12
|
+
|
|
13
|
+
`gem 'paper_trail-globalid'`
|
|
14
|
+
|
|
15
|
+
1. And then execute:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Usage
|
|
22
|
+
|
|
23
|
+
Basically this gem works on stroring global_id to whodunnit field of `PaperTrail::Version table`. As this is an additional extension installed, this will not hinder / break existing paper_trail functionalities.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
widget = Widget.find 42
|
|
27
|
+
widget.versions # [<PaperTrail::Version>, <PaperTrail::Version>, ...]
|
|
28
|
+
v = widget.versions.last
|
|
29
|
+
```
|
|
30
|
+
Now you can also store object to `PaperTrail.whodunnit=`, and if object will be instance of `ActiveRecord::Base` it will store the global id in the version's `whodunnit` column.
|
|
31
|
+
|
|
32
|
+
And you can also retrieve the actually object later just by using method `actor`.
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
admin = Admin.find(1) # <Admin:0x007fa2df9a5590>
|
|
36
|
+
|
|
37
|
+
PaperTrail.whodunnit = admin
|
|
38
|
+
PaperTrail.actor # <Admin:0x007fa2df9a5590> actual object
|
|
39
|
+
|
|
40
|
+
widget.update_attributes :name => 'Wibble'
|
|
41
|
+
widget.versions.last.whodunnit # "gid://app/Admin/1"
|
|
42
|
+
widget.versions.last.actor # retruns the actuall object
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Method `actor` will return the whodunnit value if we pass value another than `ActiveRecord` object.
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
PaperTrail.whodunnit = 'admin_name'
|
|
49
|
+
PaperTrail.actor # "admin_name"
|
|
50
|
+
|
|
51
|
+
widget.update_attributes :name => 'Wibble'
|
|
52
|
+
widget.versions.last.whodunnit # "admin_name"
|
|
53
|
+
widget.versions.last.actor # "admin_name"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Contributing
|
|
57
|
+
|
|
58
|
+
1. Fork it ( https://github.com/[my-github-username]/paper_trail-globalid/fork )
|
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "paper_trail_globalid/paper_trail"
|
|
2
|
+
require "paper_trail_globalid/version"
|
|
3
|
+
require "paper_trail_globalid/version_concern"
|
|
4
|
+
|
|
5
|
+
module PaperTrailGlobalid
|
|
6
|
+
module ::PaperTrail
|
|
7
|
+
include ::PaperTrailGlobalid::PaperTrail
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module ::PaperTrail
|
|
11
|
+
module VersionConcern
|
|
12
|
+
include ::PaperTrailGlobalid::VersionConcern
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module PaperTrailGlobalid
|
|
2
|
+
module PaperTrail
|
|
3
|
+
module ClassMethods
|
|
4
|
+
def whodunnit=(value)
|
|
5
|
+
if value.is_a? ActiveRecord::Base
|
|
6
|
+
paper_trail_store[:whodunnit] = value.to_gid
|
|
7
|
+
else
|
|
8
|
+
paper_trail_store[:whodunnit] = value
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def actor
|
|
13
|
+
::GlobalID::Locator.locate(paper_trail_store[:whodunnit]) || whodunnit
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.included(receiver)
|
|
18
|
+
receiver.extend ClassMethods
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module PaperTrailGlobalid
|
|
2
|
+
module VersionConcern
|
|
3
|
+
def whodunnit=(value)
|
|
4
|
+
if value.is_a? ActiveRecord::Base
|
|
5
|
+
super(value.to_gid)
|
|
6
|
+
else
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Returns an object which was responsible for a change
|
|
12
|
+
# you need to store global_id to whodunnit field to make this method return the object(who was responsible)
|
|
13
|
+
# for example, whodunnit => "gid://app/Order/1" then
|
|
14
|
+
# whodunnit_user will return Order.find_by(id: 1) in application scope.
|
|
15
|
+
def actor
|
|
16
|
+
::GlobalID::Locator.locate(whodunnit) || whodunnit
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'paper_trail_globalid/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "paper_trail-globalid"
|
|
8
|
+
spec.version = PaperTrailGlobalid::VERSION
|
|
9
|
+
spec.authors = ["Ankit"]
|
|
10
|
+
spec.email = ["ankit.bansal1910@gmail.com"]
|
|
11
|
+
spec.summary = "An extension to paper_trail, using this you can fetch actual object who was responsible for this change"
|
|
12
|
+
spec.description = "An extension to paper_trail, using this you can fetch actual object who was responsible for this change"
|
|
13
|
+
spec.homepage = "https://github.com/ankit1910/paper_trail-globalid"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'paper_trail', '>= 3.0.0'
|
|
22
|
+
spec.add_dependency 'globalid'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency 'appraisal', '~> 2.1'
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
26
|
+
spec.add_development_dependency "rake"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: paper_trail-globalid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2.rc
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ankit
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: paper_trail
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 3.0.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 3.0.0
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: globalid
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: appraisal
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2.1'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2.1'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.6'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ~>
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.6'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: An extension to paper_trail, using this you can fetch actual object who
|
|
84
|
+
was responsible for this change
|
|
85
|
+
email:
|
|
86
|
+
- ankit.bansal1910@gmail.com
|
|
87
|
+
executables: []
|
|
88
|
+
extensions: []
|
|
89
|
+
extra_rdoc_files: []
|
|
90
|
+
files:
|
|
91
|
+
- .gitignore
|
|
92
|
+
- Gemfile
|
|
93
|
+
- LICENSE.txt
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- lib/paper_trail_globalid.rb
|
|
97
|
+
- lib/paper_trail_globalid/paper_trail.rb
|
|
98
|
+
- lib/paper_trail_globalid/version.rb
|
|
99
|
+
- lib/paper_trail_globalid/version_concern.rb
|
|
100
|
+
- paper_trail_globalid.gemspec
|
|
101
|
+
homepage: https://github.com/ankit1910/paper_trail-globalid
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata: {}
|
|
105
|
+
post_install_message:
|
|
106
|
+
rdoc_options: []
|
|
107
|
+
require_paths:
|
|
108
|
+
- lib
|
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - '>='
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - '>'
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: 1.3.1
|
|
119
|
+
requirements: []
|
|
120
|
+
rubyforge_project:
|
|
121
|
+
rubygems_version: 2.2.2
|
|
122
|
+
signing_key:
|
|
123
|
+
specification_version: 4
|
|
124
|
+
summary: An extension to paper_trail, using this you can fetch actual object who was
|
|
125
|
+
responsible for this change
|
|
126
|
+
test_files: []
|