et_history 0.0.2

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: 7dc6102a26f124d15acd0883311154420b949557
4
+ data.tar.gz: 70b0279557833991b11b3cabcd83ed3050397c6f
5
+ SHA512:
6
+ metadata.gz: a73f19e950b88e09b894a99167052f11845a0f83c0f21bde07e4f5f4c1cb24d481f31f00926b1f0381b7f2e7f62e5366a5f0c6fccca559bf34b9887ef3e79280
7
+ data.tar.gz: 2d07b0d4435d38f7387844346a7f17c2e22f49b79df56d1b1a709125d1915bf7188e2e651049eeea4c8b7564c0ccb4cabce3d68f5dbc7322ae946aaaa1b8848a
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in et_history.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Scott Olsen
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,17 @@
1
+ # ET History
2
+
3
+ ## Installation
4
+
5
+ ### Rails 3 & 4
6
+
7
+ 1. Add PaperTrail and et history to your `Gemfile`
8
+ `gem 'paper_trail', '~> 3.0.5'`
9
+ `gem 'et_history'`
10
+
11
+ 2. Run the generator to copy over the needed files
12
+ `bundle exec rails generate et_history:install`
13
+
14
+ 3. Run the migration.
15
+ `bundle exec rake db:migrate`
16
+
17
+ 4. By default, versioning will be enabled for all models
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'et_history/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "et_history"
8
+ spec.version = EtHistory::VERSION
9
+ spec.authors = ["Scott Olsen"]
10
+ spec.email = ["solsen300@gmail.com"]
11
+ spec.summary = "Adds a history view for all models"
12
+ spec.description = "Adds a history view for all models"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0") + Dir["{lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.md"]
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "paper_trail"
25
+ end
data/lib/et_history.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "et_history/version"
2
+
3
+ module EtHistory
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module EtHistory
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module EtHistory
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ include ::Rails::Generators::Migration
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc 'Adds papertrail migration, controller, and view'
11
+
12
+ def create_migration_file
13
+ migration_template 'create_versions.rb', 'db/migrate/create_versions.rb'
14
+ end
15
+
16
+ def create_controller_file
17
+ template('history_controller.rb', "app/controllers/history_controller.rb")
18
+ end
19
+
20
+ def create_view_file
21
+ directory('history/', 'app/views/history')
22
+ # template('history_index.html.erb', "app/views/history/index.html.erb")
23
+ end
24
+
25
+ def create_model_file
26
+ template('version.rb', "app/models/version.rb")
27
+ end
28
+
29
+ def create_initializer
30
+ template('paper_trail.rb', "config/initializers/paper_trail.rb")
31
+ end
32
+
33
+
34
+ def create_routes_entry
35
+ route 'resources :history, only: :index'
36
+ end
37
+
38
+ def self.next_migration_number(dirname)
39
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
40
+ end
41
+
42
+ puts "run"
43
+ puts "rake db:migrate"
44
+ puts "drink a beer"
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ class CreateVersions < ActiveRecord::Migration
2
+ def change
3
+ create_table :versions do |t|
4
+ t.string :item_type, :null => false
5
+ t.integer :item_id, :null => false
6
+ t.string :event, :null => false
7
+ t.string :whodunnit
8
+ t.text :object
9
+ t.text :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :versions, [:item_type, :item_id]
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ <div>
2
+ <h2>Version History</h2>
3
+ <%= form_tag '/history', method: :get, class:'form-horizontal' do %>
4
+ <div class="control-group">
5
+ <%= label_tag :id, "ID", class: 'control-label' %>
6
+ <%= text_field_tag :id, params[:id] %>
7
+ </div>
8
+
9
+ <div class="control-group">
10
+ <%= label_tag :resource, "Model", class: 'control-label' %>
11
+ <%= select_tag :resource, options_for_select(Version.pluck(:item_type).uniq, params[:resource]) %>
12
+ </div>
13
+
14
+ <div class="actions well">
15
+ <%= submit_tag "Submit", class: 'btn btn-save' %>
16
+ </div>
17
+
18
+ <% end %>
19
+
20
+ <% unless @object.nil? %>
21
+ <h2>History YO!</h2>
22
+ <table>
23
+ <thead>
24
+ <tr>
25
+ <th>Who</th>
26
+ <th>Event</th>
27
+ <th>Changes</th>
28
+ <th>Date</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% @object.versions.reverse.each do |v| %>
33
+ <tr>
34
+ <td><%= User.find(v.whodunnit).email unless v.whodunnit.nil? %> </td>
35
+ <td><%= v.event %></td>
36
+ <td>
37
+ <% v.changeset.each do |k, v| %>
38
+ <div>
39
+ <%= "#{k} changed from <strong>#{v[0]}</strong> to <strong>#{v[1]}</strong>".html_safe %>
40
+ </div>
41
+ <% end %>
42
+ </td>
43
+ <td><%= v.created_at.strftime("%m/%d/%Y %I:%M %p") %></td>
44
+ </tr>
45
+ <% end %>
46
+ </tbody>
47
+ </table>
48
+ <% end %>
49
+ </div>
@@ -0,0 +1,8 @@
1
+ class HistoryController < ApplicationController
2
+ def index
3
+ unless params[:resource].nil? || params[:id].nil?
4
+ resource = Object.const_get params[:resource]
5
+ @object = resource.find(params[:id])
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ ActiveRecord::Base.module_eval do
2
+ class << self
3
+ def inherited_with_paper_trail subclass
4
+ # remember to skip it on SchemaMigration which has its own version method
5
+ skipped_models = ["ActiveRecord::SchemaMigration", "PaperTrail::Version"]
6
+ inherited_without_paper_trail subclass
7
+ unless skipped_models.include?(subclass.to_s)
8
+ subclass.send(:has_paper_trail)
9
+ end
10
+ end
11
+ alias_method_chain :inherited, :paper_trail
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class Version < ActiveRecord::Base
2
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: et_history
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Scott Olsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: paper_trail
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Adds a history view for all models
56
+ email:
57
+ - solsen300@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - et_history.gemspec
68
+ - lib/et_history.rb
69
+ - lib/et_history/version.rb
70
+ - lib/generators/et_history/install_generator.rb
71
+ - lib/generators/et_history/templates/create_versions.rb
72
+ - lib/generators/et_history/templates/history/index.html.erb
73
+ - lib/generators/et_history/templates/history_controller.rb
74
+ - lib/generators/et_history/templates/paper_trail.rb
75
+ - lib/generators/et_history/templates/version.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Adds a history view for all models
100
+ test_files: []