active_admin_versioning 0.1.0

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
+ SHA1:
3
+ metadata.gz: 4f4f86db981176222c54e415778ed9c5ca6b54f5
4
+ data.tar.gz: 2110587b8f24ca48f6f6958666f737840a71091d
5
+ SHA512:
6
+ metadata.gz: b77a791e13854d58b39adb298297d45e2472eeb5ad5a1c5e0e00c0b474072a92d24a8138b8f4cecea0647cbb28a30ba732904cbc155a44bc3acd5618b1b61df4
7
+ data.tar.gz: 53db11fd3e9a6da109d2b10b6f42fa3b02e359fa6d178d8f5ba3b08f8d724b26a2bfdc231ea5d3fcee9f3df5f52f14e716bdcf84bb1ca79b8d8ad0487edc461e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ inherit_from:
2
+ - .ruby-style.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - "bin/*"
7
+ - "vendor/**/*"
8
+ - Gemfile
9
+ - Rakefile
10
+ DisplayCopNames: true
11
+ TargetRubyVersion: 2.1
12
+
13
+ Metrics/LineLength:
14
+ Enabled: false
data/.ruby-style.yml ADDED
@@ -0,0 +1,242 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "vendor/**/*"
4
+ UseCache: false
5
+ Style/CollectionMethods:
6
+ Description: Preferred collection methods.
7
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
8
+ Enabled: true
9
+ PreferredMethods:
10
+ collect: map
11
+ collect!: map!
12
+ find: detect
13
+ find_all: select
14
+ reduce: inject
15
+ Style/DotPosition:
16
+ Description: Checks the position of the dot in multi-line method calls.
17
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
18
+ Enabled: true
19
+ EnforcedStyle: trailing
20
+ SupportedStyles:
21
+ - leading
22
+ - trailing
23
+ Style/FileName:
24
+ Description: Use snake_case for source file names.
25
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
26
+ Enabled: false
27
+ Exclude: []
28
+ Style/GuardClause:
29
+ Description: Check for conditionals that can be replaced with guard clauses
30
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
31
+ Enabled: false
32
+ MinBodyLength: 1
33
+ Style/IfUnlessModifier:
34
+ Description: Favor modifier if/unless usage when you have a single-line body.
35
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
36
+ Enabled: false
37
+ MaxLineLength: 80
38
+ Style/OptionHash:
39
+ Description: Don't use option hashes when you can use keyword arguments.
40
+ Enabled: false
41
+ Style/PercentLiteralDelimiters:
42
+ Description: Use `%`-literal delimiters consistently
43
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
44
+ Enabled: false
45
+ PreferredDelimiters:
46
+ "%": "()"
47
+ "%i": "()"
48
+ "%q": "()"
49
+ "%Q": "()"
50
+ "%r": "{}"
51
+ "%s": "()"
52
+ "%w": "()"
53
+ "%W": "()"
54
+ "%x": "()"
55
+ Style/PredicateName:
56
+ Description: Check the names of predicate methods.
57
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
58
+ Enabled: true
59
+ NamePrefix:
60
+ - is_
61
+ - has_
62
+ - have_
63
+ NamePrefixBlacklist:
64
+ - is_
65
+ Exclude:
66
+ - spec/**/*
67
+ Style/RaiseArgs:
68
+ Description: Checks the arguments passed to raise/fail.
69
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
70
+ Enabled: false
71
+ EnforcedStyle: exploded
72
+ SupportedStyles:
73
+ - compact
74
+ - exploded
75
+ Style/SignalException:
76
+ Description: Checks for proper usage of fail and raise.
77
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
78
+ Enabled: false
79
+ EnforcedStyle: semantic
80
+ SupportedStyles:
81
+ - only_raise
82
+ - only_fail
83
+ - semantic
84
+ Style/SingleLineBlockParams:
85
+ Description: Enforces the names of some block params.
86
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
87
+ Enabled: false
88
+ Methods:
89
+ - reduce:
90
+ - a
91
+ - e
92
+ - inject:
93
+ - a
94
+ - e
95
+ Style/SingleLineMethods:
96
+ Description: Avoid single-line methods.
97
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
98
+ Enabled: false
99
+ AllowIfMethodIsEmpty: true
100
+ Style/StringLiterals:
101
+ Description: Checks if uses of quotes match the configured preference.
102
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
103
+ Enabled: true
104
+ EnforcedStyle: double_quotes
105
+ SupportedStyles:
106
+ - single_quotes
107
+ - double_quotes
108
+ Style/StringLiteralsInInterpolation:
109
+ Description: Checks if uses of quotes inside expressions in interpolated strings
110
+ match the configured preference.
111
+ Enabled: true
112
+ EnforcedStyle: single_quotes
113
+ SupportedStyles:
114
+ - single_quotes
115
+ - double_quotes
116
+ Style/TrailingCommaInArguments:
117
+ Description: 'Checks for trailing comma in argument lists.'
118
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
119
+ Enabled: false
120
+ EnforcedStyleForMultiline: no_comma
121
+ SupportedStyles:
122
+ - comma
123
+ - consistent_comma
124
+ - no_comma
125
+ Style/TrailingCommaInLiteral:
126
+ Description: 'Checks for trailing comma in array and hash literals.'
127
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
128
+ Enabled: false
129
+ EnforcedStyleForMultiline: no_comma
130
+ SupportedStyles:
131
+ - comma
132
+ - consistent_comma
133
+ - no_comma
134
+ Metrics/AbcSize:
135
+ Description: A calculated magnitude based on number of assignments, branches, and
136
+ conditions.
137
+ Enabled: false
138
+ Max: 15
139
+ Metrics/ClassLength:
140
+ Description: Avoid classes longer than 100 lines of code.
141
+ Enabled: false
142
+ CountComments: false
143
+ Max: 100
144
+ Metrics/ModuleLength:
145
+ CountComments: false
146
+ Max: 100
147
+ Description: Avoid modules longer than 100 lines of code.
148
+ Enabled: false
149
+ Metrics/CyclomaticComplexity:
150
+ Description: A complexity metric that is strongly correlated to the number of test
151
+ cases needed to validate a method.
152
+ Enabled: false
153
+ Max: 6
154
+ Metrics/MethodLength:
155
+ Description: Avoid methods longer than 10 lines of code.
156
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
157
+ Enabled: false
158
+ CountComments: false
159
+ Max: 10
160
+ Metrics/ParameterLists:
161
+ Description: Avoid parameter lists longer than three or four parameters.
162
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
163
+ Enabled: false
164
+ Max: 5
165
+ CountKeywordArgs: true
166
+ Metrics/PerceivedComplexity:
167
+ Description: A complexity metric geared towards measuring complexity for a human
168
+ reader.
169
+ Enabled: false
170
+ Max: 7
171
+ Lint/AssignmentInCondition:
172
+ Description: Don't use assignment in conditions.
173
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
174
+ Enabled: false
175
+ AllowSafeAssignment: true
176
+ Style/InlineComment:
177
+ Description: Avoid inline comments.
178
+ Enabled: false
179
+ Style/AccessorMethodName:
180
+ Description: Check the naming of accessor methods for get_/set_.
181
+ Enabled: false
182
+ Style/Alias:
183
+ Description: Use alias_method instead of alias.
184
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
185
+ Enabled: false
186
+ Style/Documentation:
187
+ Description: Document classes and non-namespace modules.
188
+ Enabled: false
189
+ Style/DoubleNegation:
190
+ Description: Checks for uses of double negation (!!).
191
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
192
+ Enabled: false
193
+ Style/EachWithObject:
194
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
195
+ Enabled: false
196
+ Style/EmptyLiteral:
197
+ Description: Prefer literals to Array.new/Hash.new/String.new.
198
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
199
+ Enabled: false
200
+ Style/ModuleFunction:
201
+ Description: Checks for usage of `extend self` in modules.
202
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
203
+ Enabled: false
204
+ Style/OneLineConditional:
205
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
206
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
207
+ Enabled: false
208
+ Style/PerlBackrefs:
209
+ Description: Avoid Perl-style regex back references.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
211
+ Enabled: false
212
+ Style/Send:
213
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
214
+ may overlap with existing methods.
215
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
216
+ Enabled: false
217
+ Style/SpecialGlobalVars:
218
+ Description: Avoid Perl-style global variables.
219
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
220
+ Enabled: false
221
+ Style/VariableInterpolation:
222
+ Description: Don't interpolate global, instance and class variables directly in
223
+ strings.
224
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
225
+ Enabled: false
226
+ Style/WhenThen:
227
+ Description: Use when x then ... for one-line cases.
228
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
229
+ Enabled: false
230
+ Lint/EachWithObjectArgument:
231
+ Description: Check for immutable argument given to each_with_object.
232
+ Enabled: true
233
+ Lint/HandleExceptions:
234
+ Description: Don't suppress exception.
235
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
236
+ Enabled: false
237
+ Lint/LiteralInCondition:
238
+ Description: Checks of literals used in conditions.
239
+ Enabled: false
240
+ Lint/LiteralInInterpolation:
241
+ Description: Checks for literals used in interpolation.
242
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_admin_versioning.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Yoshiyuki Hirano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # ActiveAdminVersioning
2
+
3
+ Good for auditing or versioning for [Active Admin](https://github.com/activeadmin/activeadmin) (using [PaperTrail](https://github.com/airblade/paper_trail))
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_admin_versioning'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Recipe for Rails 5
18
+
19
+ 1. Add necessary gems to `Gemfile` and `bundle`:
20
+
21
+ ```ruby
22
+ gem 'activeadmin', github: 'activeadmin'
23
+ gem 'devise'
24
+ gem 'inherited_resources', github: 'activeadmin/inherited_resources'
25
+ gem 'paper_trail', '~> 5.2.0'
26
+ gem 'active_admin_versioning'
27
+ ```
28
+
29
+ 2. Install Active Admin and Paper Trail:
30
+
31
+ ```sh
32
+ $ bin/rails generate active_admin:install
33
+ $ bin/rails generate paper_trail:install
34
+ $ bin/rails db:create db:migrate db:seed
35
+ ```
36
+
37
+ 3. Add module of Paper Trail to `AdminUser`:
38
+
39
+ ```ruby
40
+ class AdminUser < ApplicationRecord
41
+ has_paper_trail
42
+ end
43
+ ```
44
+
45
+ 4. Run server `bin/rails server` and open [localhost:3000](http://localhost:3000/admin)
46
+
47
+ ![](https://cloud.githubusercontent.com/assets/15371677/20568714/b163df5e-b1e0-11e6-910d-198ece1e80f5.png)
48
+
49
+ ![](https://cloud.githubusercontent.com/assets/15371677/20568746/cff3ccfe-b1e0-11e6-96b8-00d8bc241a4e.png)
50
+
51
+ ## License
52
+
53
+ [MIT License](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "active_admin_versioning/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "active_admin_versioning"
8
+ gem.version = ActiveAdminVersioning::VERSION
9
+ gem.authors = ["Yoshiyuki Hirano"]
10
+ gem.email = ["yhirano@me.com"]
11
+
12
+ gem.summary = "Good for auditing or versioning for Active Admin"
13
+ gem.description = gem.summary
14
+ gem.homepage = "https://github.com/yhirano55/active_admin_versioning"
15
+ gem.license = "MIT"
16
+
17
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ gem.bindir = "bin"
19
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.required_ruby_version = ">= 2.1.0"
23
+
24
+ gem.add_runtime_dependency "activeadmin", ">= 1.0.0.pre4"
25
+ gem.add_runtime_dependency "paper_trail", ">= 4.2.0"
26
+
27
+ gem.add_development_dependency "bundler", "~> 1.13"
28
+ gem.add_development_dependency "rake", "~> 10.0"
29
+ gem.add_development_dependency "rspec", "~> 3.0"
30
+ gem.add_development_dependency "pry", "~> 0.10.0"
31
+ gem.add_development_dependency "rubocop", "~> 0.40.0"
32
+ end
@@ -0,0 +1,14 @@
1
+ paginated_collection(versions, display_total: false, download_links: false) do
2
+ table_for(versions, i18n: ::PaperTrail::Version, class: "index_table") do
3
+ column(:id)
4
+ column(:whodunnit) do |record|
5
+ record.whodunnit.presence || t("views.version.unknown_user")
6
+ end
7
+ column(:event, :event_i18n)
8
+ column(:item_type, :item_class_i18n)
9
+ column(:object) do |record|
10
+ record.item_instance ? attributes_table_for(record.item_instance, *record.item_column_names) : nil
11
+ end
12
+ column(:created_at)
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ <%= link_to_unless current_page.first?, t('views.version.pagination.last').html_safe, url, class: :table_tools_button %>
@@ -0,0 +1 @@
1
+ <%= link_to_unless current_page.last?, t('views.version.pagination.previous').html_safe, url, rel: 'previous', class: :table_tools_button %>
@@ -0,0 +1,5 @@
1
+ <%= paginator.render do -%>
2
+ <%= next_page_tag unless current_page.last? %>
3
+ <%= prev_page_tag unless current_page.first? %>
4
+ <%= first_page_tag unless current_page.first? %>
5
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= link_to_unless current_page.first?, t('views.version.pagination.next').html_safe, url, rel: 'next', class: :table_tools_button %>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_admin_versioning"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ paper_trail/version: Version
5
+ attributes:
6
+ paper_trail/version:
7
+ id: ID
8
+ event: Event
9
+ whodunnit: Whodunnit
10
+ object: Object
11
+ created_at: Created at
12
+ views:
13
+ version:
14
+ empty: "This record doesn't have any %{model_name}"
15
+ event:
16
+ create: create
17
+ destroy: destroy
18
+ update: update
19
+ pagination:
20
+ last: "Last &raquo;"
21
+ next: "Next &rsaquo;"
22
+ previous: "&lsaquo; Prev"
23
+ unknown_user: "unknown user"
@@ -0,0 +1,23 @@
1
+ ja:
2
+ activerecord:
3
+ models:
4
+ paper_trail/version: バージョン
5
+ attributes:
6
+ paper_trail/version:
7
+ id: ID
8
+ event: 操作
9
+ whodunnit: 実行者
10
+ object: 内容
11
+ created_at: 実行日時
12
+ views:
13
+ version:
14
+ empty: "%{model_name}は何もありません"
15
+ event:
16
+ create: 作成
17
+ destroy: 削除
18
+ update: 更新
19
+ pagination:
20
+ last: "最新 &raquo;"
21
+ next: "次 &rsaquo;"
22
+ previous: "&lsaquo; 前"
23
+ unknown_user: "unknown user"
@@ -0,0 +1,2 @@
1
+ require "active_admin_versioning/engine"
2
+ require "active_admin_versioning/version"
@@ -0,0 +1,16 @@
1
+ require "rails"
2
+
3
+ module ActiveAdminVersioning
4
+ class Engine < ::Rails::Engine
5
+ config.after_initialize do
6
+ require "active_admin_versioning/extension/application"
7
+ require "active_admin_versioning/extension/dsl"
8
+ require "active_admin_versioning/extension/resource_controller"
9
+ require "active_admin_versioning/extension/paper_trail"
10
+
11
+ ::ActiveAdmin::Application.send :prepend, ActiveAdminVersioning::Extension::Application
12
+ ::ActiveAdmin::DSL.send :include, ActiveAdminVersioning::Extension::DSL
13
+ ::PaperTrail::Version.send :include, ActiveAdminVersioning::Extension::PaperTrail
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveAdminVersioning
2
+ module Extension
3
+ module Application
4
+ def register(*arg, &block)
5
+ super(*arg) do
6
+ versioning
7
+ instance_eval(&block)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ module ActiveAdminVersioning
2
+ module Extension
3
+ module DSL
4
+ def versioning
5
+ return unless config.resource_class.try(:paper_trail_enabled_for_model?)
6
+
7
+ controller { include ActiveAdminVersioning::Extension::ResourceController }
8
+
9
+ member_action(:versions) do
10
+ @versions = resource.versions.reorder(id: :desc, created_at: :desc).page(params[:page])
11
+ @page_title = ::PaperTrail::Version.model_name.human
12
+ render "versions"
13
+ end
14
+
15
+ action_item(:version, only: :show) do
16
+ link_to send("versions_admin_#{resource_instance_name}_path") do
17
+ ::PaperTrail::Version.model_name.human
18
+ end
19
+ end
20
+
21
+ sidebar(::PaperTrail::Version.model_name.human, only: :show) do
22
+ if versions.present?
23
+ attributes_table_for versions[0] do
24
+ row(::PaperTrail::Version.model_name.human) { |_| version_number }
25
+ row(:event, &:event_i18n)
26
+ row(:whodunnit) do |record|
27
+ record.whodunnit.presence || span(t("views.version.unknown_user"), class: "empty")
28
+ end
29
+ row(:created_at)
30
+ end
31
+ paginate(versions, theme: :version)
32
+ else
33
+ I18n.t("views.version.empty", model_name: ::PaperTrail::Version.model_name.human)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require "yaml"
2
+
3
+ module ActiveAdminVersioning
4
+ module Extension
5
+ module PaperTrail
6
+ def item_class
7
+ item_type.safe_constantize
8
+ end
9
+
10
+ def item_class_i18n
11
+ item_class.try(:model_name).try(:human) || item_type
12
+ end
13
+
14
+ def item_column_names
15
+ item_class.column_names
16
+ end
17
+
18
+ def item_attributes
19
+ YAML.load(object).slice(*item_column_names)
20
+ rescue
21
+ nil
22
+ end
23
+
24
+ def item_instance
25
+ @item_instance ||= item_buildable? ? item_class.new(item_attributes) : nil
26
+ end
27
+
28
+ def event_i18n
29
+ I18n.t("views.version.event.#{event}", default: event)
30
+ end
31
+
32
+ private
33
+
34
+ def item_buildable?
35
+ item_class && item_attributes
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveAdminVersioning
2
+ module Extension
3
+ module ResourceController
4
+ def self.included(base)
5
+ base.before_action(:set_paper_trail_whodunnit)
6
+ end
7
+
8
+ def show
9
+ page = params[:page].to_i
10
+ @versions = resource.versions.reorder(id: :desc, created_at: :desc).page(params[:page]).per(1)
11
+ @version_number = page > 0 ? @versions.total_count - (page - 1) : @versions.total_count
12
+ set_resource_ivar(@versions[0].reify) if @versions.present?
13
+ show!
14
+ end
15
+
16
+ protected
17
+
18
+ def user_for_paper_trail
19
+ current_admin_user.try(:id) || t("views.version.unknown_user")
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminVersioning
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_versioning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiyuki Hirano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0.pre4
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.0.pre4
27
+ - !ruby/object:Gem::Dependency
28
+ name: paper_trail
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.40.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.40.0
111
+ description: Good for auditing or versioning for Active Admin
112
+ email:
113
+ - yhirano@me.com
114
+ executables:
115
+ - console
116
+ - setup
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-style.yml"
124
+ - ".travis.yml"
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - active_admin_versioning.gemspec
130
+ - app/views/application/versions.html.arb
131
+ - app/views/kaminari/version/_first_page.html.erb
132
+ - app/views/kaminari/version/_next_page.html.erb
133
+ - app/views/kaminari/version/_paginator.html.erb
134
+ - app/views/kaminari/version/_prev_page.html.erb
135
+ - bin/console
136
+ - bin/setup
137
+ - config/locales/en.yml
138
+ - config/locales/ja.yml
139
+ - lib/active_admin_versioning.rb
140
+ - lib/active_admin_versioning/engine.rb
141
+ - lib/active_admin_versioning/extension/application.rb
142
+ - lib/active_admin_versioning/extension/dsl.rb
143
+ - lib/active_admin_versioning/extension/paper_trail.rb
144
+ - lib/active_admin_versioning/extension/resource_controller.rb
145
+ - lib/active_admin_versioning/version.rb
146
+ homepage: https://github.com/yhirano55/active_admin_versioning
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: 2.1.0
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Good for auditing or versioning for Active Admin
170
+ test_files: []