hist 0.2.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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +30 -0
  3. data/README.md +235 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/hist_manifest.js +2 -0
  6. data/app/assets/javascripts/hist/application.js +18 -0
  7. data/app/assets/javascripts/hist/vendor/ace-diff/ace-diff.min.js +2 -0
  8. data/app/assets/javascripts/hist/vendor/bootstrap/bootstrap.min.js +7 -0
  9. data/app/assets/javascripts/hist/vendor/bootstrap/popper.min.js +5 -0
  10. data/app/assets/javascripts/hist/version_diff.js +64 -0
  11. data/app/assets/stylesheets/hist/application.css +16 -0
  12. data/app/assets/stylesheets/hist/default.scss +20 -0
  13. data/app/assets/stylesheets/hist/vendor/ace-diff/ace-diff.min.css +2 -0
  14. data/app/controllers/hist/application_controller.rb +71 -0
  15. data/app/controllers/hist/pendings_controller.rb +21 -0
  16. data/app/controllers/hist/versions_controller.rb +171 -0
  17. data/app/helpers/hist/application_helper.rb +4 -0
  18. data/app/jobs/hist/application_job.rb +4 -0
  19. data/app/mailers/hist/application_mailer.rb +6 -0
  20. data/app/models/hist/application_record.rb +389 -0
  21. data/app/models/hist/config.rb +10 -0
  22. data/app/models/hist/hist_config.rb +124 -0
  23. data/app/models/hist/model.rb +214 -0
  24. data/app/models/hist/pending.rb +53 -0
  25. data/app/models/hist/version.rb +20 -0
  26. data/app/views/hist/_modal_popup.html.erb +29 -0
  27. data/app/views/hist/versions/diff.js.erb +53 -0
  28. data/app/views/layouts/hist/application.html.erb +16 -0
  29. data/app/views/partials/hist/_modal.html.erb +1 -0
  30. data/config/routes.rb +8 -0
  31. data/lib/generators/hist/db_generator.rb +39 -0
  32. data/lib/generators/hist/initializer_generator.rb +15 -0
  33. data/lib/generators/hist/install_generator.rb +29 -0
  34. data/lib/generators/hist/routes_generator.rb +29 -0
  35. data/lib/generators/hist/templates/db/create_hist_pendings.rb.erb +40 -0
  36. data/lib/generators/hist/templates/db/create_hist_versions.rb.erb +40 -0
  37. data/lib/generators/hist/templates/init/hist.rb +9 -0
  38. data/lib/hist.rb +19 -0
  39. data/lib/hist/engine.rb +33 -0
  40. data/lib/hist/versionnumber.rb +3 -0
  41. data/lib/tasks/hist_tasks.rake +4 -0
  42. metadata +156 -0
@@ -0,0 +1,53 @@
1
+ $('#hist-gem-modal').html("<%= j(render partial: 'hist/modal_popup') %>");
2
+ $('#hist-gem-modal').modal('show');
3
+
4
+ <% if @aceMode == :json %>
5
+
6
+ $(function() {
7
+ var mode = "ace/mode/json";
8
+
9
+ var left_content = JSON.stringify(<%= @diff_escaped[:left].html_safe %>, null, '\t');
10
+ var right_content = JSON.stringify(<%= @diff_escaped[:right].html_safe %>, null, '\t');
11
+
12
+ histInstantiateHistory(mode, "<%=@height%>", left_content, right_content);
13
+ });
14
+
15
+ <% elsif @aceMode == :yaml %>
16
+
17
+ $(function() {
18
+ var mode = "ace/mode/yaml";
19
+ var left_content = `<%= YAML.dump(@diff[:left]) %>`;
20
+ var right_content = `<%= YAML.dump(@diff[:right]) %>`;
21
+
22
+ histInstantiateHistory(mode, "<%=@height%>", left_content, right_content);
23
+ });
24
+
25
+ <% elsif @aceMode == :text %>
26
+
27
+ $(function() {
28
+ var mode = "ace/mode/text";
29
+ var left_content = `<%= @diff[:left].to_s %>`;
30
+ var right_content = `<%= @diff[:right].to_s %>`;
31
+
32
+ histInstantiateHistory(mode, "<%=@height%>", left_content, right_content);
33
+
34
+ // ActiveSupport::JSON.decode(@diff[:version])["doc_files"].first["ocr"].to_s
35
+ // ActiveSupport::JSON.decode(@diff[:current])["doc_files"].first["ocr"].to_s,
36
+ });
37
+
38
+ <% elsif @aceMode == :html %>
39
+
40
+ $(function() {
41
+ var mode = "ace/mode/html";
42
+ var left_content = `<%= @diff[:left].html_safe %>`;
43
+ var right_content = `<%= @diff[:right].html_safe %>`;
44
+
45
+ histInstantiateHistory(mode, "<%=@height%>", left_content, right_content);
46
+
47
+ // ActiveSupport::JSON.decode(@diff[:version])["doc_files"].first["ocr"].to_s
48
+ // ActiveSupport::JSON.decode(@diff[:current])["doc_files"].first["ocr"].to_s,
49
+ });
50
+
51
+ <% end %>
52
+
53
+
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Hist</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "hist/application", media: "all" %>
9
+ <%= javascript_include_tag "hist/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1 @@
1
+ <div class="modal fade" id="hist-gem-modal" tabindex="-1" role="dialog" data-backdrop="static" aria-hidden="true" data-keyboard="false">Loading...</div>
@@ -0,0 +1,8 @@
1
+ Hist::Engine.routes.draw do
2
+
3
+ resources :versions, path: :version, except: :index do
4
+ collection do
5
+ get 'diff'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/generators'
2
+ require "rails/generators/migration"
3
+ require "active_record"
4
+ require "rails/generators/active_record"
5
+
6
+ # Based on: https://github.com/ankane/blazer/blob/master/lib/generators/blazer/install_generator.rb
7
+ module Hist
8
+ class DbGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+
11
+ source_root File.expand_path('../templates', __FILE__)
12
+
13
+ # Implement the required interface for Rails::Generators::Migration.
14
+ def self.next_migration_number(dirname) #:nodoc:
15
+ next_migration_number = current_migration_number(dirname) + 1
16
+ if ActiveRecord::Base.timestamped_migrations
17
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
18
+ else
19
+ "%.3d" % next_migration_number
20
+ end
21
+ end
22
+
23
+ def copy_migration
24
+ [
25
+ "create_hist_versions",
26
+ "create_hist_pendings"
27
+ ].each do |name|
28
+ migration_template "db/#{name}.rb.erb", "db/migrate/#{name}.rb", migration_version: migration_version if Dir.glob("db/migrate/*_#{name}.rb").empty?
29
+ end
30
+ end
31
+
32
+ def migration_version
33
+ if ActiveRecord::VERSION::MAJOR >= 5
34
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+
3
+ module Hist
4
+ class InitializerGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ desc 'Model Generator Hist Engine'
9
+
10
+ def config_initializer_copy
11
+ copy_file 'init/hist.rb', 'config/initializers/hist.rb' unless File::exists?('config/initializers/hist.rb')
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators'
2
+
3
+ module Hist
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ desc "InstallGenerator Hist Engine"
9
+
10
+ def copy_initializers
11
+ generate 'hist:initializer'
12
+ end
13
+
14
+ def generate_migration_scripts
15
+ generate 'hist:db'
16
+ end
17
+
18
+ def insert_to_routes
19
+ generate 'hist:routes'
20
+ end
21
+
22
+ def bundle_install
23
+ Bundler.with_clean_env do
24
+ run 'bundle install'
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails/generators'
2
+
3
+ module Hist
4
+ class RoutesGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ desc """
9
+ This generator makes the following changes to your application:
10
+ 1. Injects route declarations into your routes.rb
11
+ """
12
+
13
+ # Add auditsdb to the routes
14
+ def inject_hist_routes
15
+ unless IO.read("config/routes.rb").include?('Hist::Engine')
16
+ marker = 'Rails.application.routes.draw do'
17
+ insert_into_file "config/routes.rb", :after => marker do
18
+ %q{
19
+ # routes for Hist
20
+ mount Hist::Engine => '/hist'
21
+ }
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
+ # The largest text column available in all supported RDBMS is
3
+ # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
4
+ # so that MySQL will use `longtext` instead of `text`. Otherwise,
5
+ # when serializing very large objects, `text` might not be big enough.
6
+ TEXT_BYTES = 1_073_741_823
7
+
8
+ def change
9
+ unless ActiveRecord::Base.connection.table_exists?(:hist_pendings)
10
+ create_table :hist_pendings do |t|
11
+ t.string :model, {:null=>false}
12
+ t.integer :obj_id
13
+ t.string :whodunnit
14
+ t.string :extra
15
+ t.text :data, limit: TEXT_BYTES
16
+ t.datetime :discarded_at
17
+
18
+ # Known issue in MySQL: fractional second precision
19
+ # -------------------------------------------------
20
+ #
21
+ # MySQL timestamp columns do not support fractional seconds unless
22
+ # defined with "fractional seconds precision". MySQL users should manually
23
+ # add fractional seconds precision to this migration, specifically, to
24
+ # the `created_at` column.
25
+ # (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
26
+ #
27
+ # MySQL users should also upgrade to rails 4.2, which is the first
28
+ # version of ActiveRecord with support for fractional seconds in MySQL.
29
+ # (https://github.com/rails/rails/pull/14359)
30
+ #
31
+ t.datetime :created_at, limit: 6
32
+ end
33
+ add_index :hist_pendings, %i(model obj_id)
34
+
35
+ unless index_exists? :hist_pendings, [:discarded_at], name: 'hist_pending_discarded_idy'
36
+ add_index :hist_pendings, [:discarded_at], name: 'hist_pending_discarded_idy'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
+ # The largest text column available in all supported RDBMS is
3
+ # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
4
+ # so that MySQL will use `longtext` instead of `text`. Otherwise,
5
+ # when serializing very large objects, `text` might not be big enough.
6
+ TEXT_BYTES = 1_073_741_823
7
+
8
+ def change
9
+ unless ActiveRecord::Base.connection.table_exists?(:hist_versions)
10
+ create_table :hist_versions do |t|
11
+ t.string :model, {:null=>false}
12
+ t.integer :obj_id, null: false
13
+ t.string :whodunnit
14
+ t.string :extra
15
+ t.text :data, limit: TEXT_BYTES
16
+ t.datetime :discarded_at
17
+
18
+ # Known issue in MySQL: fractional second precision
19
+ # -------------------------------------------------
20
+ #
21
+ # MySQL timestamp columns do not support fractional seconds unless
22
+ # defined with "fractional seconds precision". MySQL users should manually
23
+ # add fractional seconds precision to this migration, specifically, to
24
+ # the `created_at` column.
25
+ # (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
26
+ #
27
+ # MySQL users should also upgrade to rails 4.2, which is the first
28
+ # version of ActiveRecord with support for fractional seconds in MySQL.
29
+ # (https://github.com/rails/rails/pull/14359)
30
+ #
31
+ t.datetime :created_at, limit: 6
32
+ end
33
+ add_index :hist_versions, %i(model obj_id)
34
+
35
+ unless index_exists? :hist_versions, [:discarded_at], name: 'hist_version_discarded_idy'
36
+ add_index :hist_versions, [:discarded_at], name: 'hist_version_discarded_idy'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ Hist.config do |conf|
2
+ conf.default_diff_exclude = []
3
+ conf.default_diff_exclude << 'created_at'
4
+ conf.default_diff_exclude << 'hist_extra'
5
+ conf.default_diff_exclude << 'whodunnit'
6
+ conf.default_diff_exclude << 'pending_id'
7
+ conf.default_diff_exclude << 'ver_id'
8
+ conf.default_diff_exclude << 'discarded_at'
9
+ end
@@ -0,0 +1,19 @@
1
+ require "hist/engine"
2
+
3
+ module Hist
4
+ # Your code goes here...
5
+
6
+ def self.model(obj:nil,klass:nil)
7
+ unless obj.nil?
8
+ return obj.class.base_class.name
9
+ end
10
+ return klass.base_class.name
11
+ end
12
+
13
+ def self.config
14
+ @config ||= Hist::Config.instance
15
+ yield @config if block_given?
16
+ @config
17
+ end
18
+
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'discard'
2
+ require 'digest'
3
+
4
+ module Hist
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Hist
7
+
8
+ engine_name 'hist'
9
+
10
+ config.autoload_paths += %W(
11
+ #{config.root}/app/controllers/concerns
12
+ #{config.root}/app/models/concerns
13
+ #{config.root}/lib/form_builders
14
+ #{config.root}/app/workers
15
+ )
16
+
17
+ initializer "hist" do |app|
18
+ # use a proc instead of a string
19
+ app.config.assets.precompile << proc { |path| path =~ /\hist\/.+\.(eot|svg|ttf|woff|png|css|js)\z/ }
20
+ end
21
+
22
+ # Could we just run "load_tasks" here instead?
23
+ # This makes our rake tasks visible.
24
+ rake_tasks do
25
+ Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..'))) do
26
+ Dir.glob(File.join('tasks', '*.rake')).each do |railtie|
27
+ load railtie
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Hist
2
+ VERSIONNUMBER = '0.2.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hist do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Anderson
8
+ - Akamai Technologies
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: ace-rails-ap
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: jquery-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: discard
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: sqlite3
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Detailed version tracking of an item and its associations in Ruby on
85
+ Rails. Based on Papertrail but with better association handling.
86
+ email:
87
+ - stevencanderson@hotmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - MIT-LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - app/assets/config/hist_manifest.js
96
+ - app/assets/javascripts/hist/application.js
97
+ - app/assets/javascripts/hist/vendor/ace-diff/ace-diff.min.js
98
+ - app/assets/javascripts/hist/vendor/bootstrap/bootstrap.min.js
99
+ - app/assets/javascripts/hist/vendor/bootstrap/popper.min.js
100
+ - app/assets/javascripts/hist/version_diff.js
101
+ - app/assets/stylesheets/hist/application.css
102
+ - app/assets/stylesheets/hist/default.scss
103
+ - app/assets/stylesheets/hist/vendor/ace-diff/ace-diff.min.css
104
+ - app/controllers/hist/application_controller.rb
105
+ - app/controllers/hist/pendings_controller.rb
106
+ - app/controllers/hist/versions_controller.rb
107
+ - app/helpers/hist/application_helper.rb
108
+ - app/jobs/hist/application_job.rb
109
+ - app/mailers/hist/application_mailer.rb
110
+ - app/models/hist/application_record.rb
111
+ - app/models/hist/config.rb
112
+ - app/models/hist/hist_config.rb
113
+ - app/models/hist/model.rb
114
+ - app/models/hist/pending.rb
115
+ - app/models/hist/version.rb
116
+ - app/views/hist/_modal_popup.html.erb
117
+ - app/views/hist/versions/diff.js.erb
118
+ - app/views/layouts/hist/application.html.erb
119
+ - app/views/partials/hist/_modal.html.erb
120
+ - config/routes.rb
121
+ - lib/generators/hist/db_generator.rb
122
+ - lib/generators/hist/initializer_generator.rb
123
+ - lib/generators/hist/install_generator.rb
124
+ - lib/generators/hist/routes_generator.rb
125
+ - lib/generators/hist/templates/db/create_hist_pendings.rb.erb
126
+ - lib/generators/hist/templates/db/create_hist_versions.rb.erb
127
+ - lib/generators/hist/templates/init/hist.rb
128
+ - lib/hist.rb
129
+ - lib/hist/engine.rb
130
+ - lib/hist/versionnumber.rb
131
+ - lib/tasks/hist_tasks.rake
132
+ homepage: https://github.com/scande3/hist
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Detailed version tracking of an item and its associations in Ruby on Rails.
155
+ Based on Papertrail.
156
+ test_files: []