validation_tracker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31fad6cf66f39d0e063d01f59016464d5519bb4b
4
+ data.tar.gz: 0637e6c5c276b0aa999ce04157581aae1958f087
5
+ SHA512:
6
+ metadata.gz: 23352a1fa0a11be309015ceb6a23227c31afd1e8f84bb452438964a85080f50af35a4006e7a312cb620afa02a751dd2b6622ef78a87a634b745c95e290993a0b
7
+ data.tar.gz: 5c91309254a3a8a204dbe0c7587493271b0a7a647b22791d539b78650f0844ca89f99ed89f0eadff26ef7cdad2b8f91d91d10cff3929c3948580e103282a7893
@@ -0,0 +1,29 @@
1
+ # taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+ require 'active_record'
5
+ require 'rails/generators/active_record'
6
+
7
+ module ValidationTracker
8
+ module Generators
9
+ class InstallGenerator < Rails::Generators::Base
10
+ include Rails::Generators::Migration
11
+
12
+ source_root File.expand_path('../templates', __FILE__)
13
+
14
+ # Implement the required interface for Rails::Generators::Migration.
15
+ def self.next_migration_number(dirname) #:nodoc:
16
+ next_migration_number = current_migration_number(dirname) + 1
17
+ if ActiveRecord::Base.timestamped_migrations
18
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
19
+ else
20
+ "%.3d" % next_migration_number
21
+ end
22
+ end
23
+
24
+ def copy_migration
25
+ migration_template 'install.rb', 'db/migrate/install_validation_tracker_attempts.rb'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :validation_tracker_attempts do |t|
4
+ t.boolean :succeeded, default: false
5
+ t.string :klass, null: false
6
+ t.text :failed
7
+ t.text :backtrace
8
+ t.timestamps
9
+ end
10
+ commit_db_transaction
11
+ add_index :validation_tracker_attempts, :klass
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'validation_tracker/version'
2
+ require 'validation_tracker/model'
3
+ require 'validation_tracker/attempt'
4
+
5
+ module ValidationTracker
6
+ end
@@ -0,0 +1,13 @@
1
+ module ValidationTracker
2
+ class Attempt < ActiveRecord::Base
3
+ self.table_name = 'validation_tracker_attempts'
4
+
5
+ serialize :backtrace, Array
6
+ serialize :failed, Hash
7
+
8
+ scope :succeeded, -> { where(succeeded: true) }
9
+ scope :failed, -> { where(succeeded: false) }
10
+
11
+ scope :on_klass, -> (klass) { where(klass: klass) }
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module ValidationTracker
2
+ module Model
3
+
4
+ def valid?(context = nil)
5
+ track(super)
6
+ end
7
+
8
+ private
9
+
10
+ def track(ouput)
11
+ backtrace
12
+ Thread.new do
13
+ ActiveRecord::Base.connection_pool.with_connection do
14
+ Attempt.create(
15
+ failed: self.errors.to_hash,
16
+ klass: self.class,
17
+ backtrace: backtrace,
18
+ succeeded: ouput
19
+ )
20
+ end
21
+ end
22
+
23
+ ouput
24
+ end
25
+
26
+ def backtrace
27
+ @backtrace ||= Thread.current.backtrace.select do |line|
28
+ !(line.split('/') & %w(validation_tracker gems)).present?
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module ValidationTracker
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validation_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barnett Klane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-21 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: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: Tracks each validation error, providing an aggregate to identify UI issues
28
+ email:
29
+ - bk@thecodery.co
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/generators/validation_tracker/install_generator.rb
35
+ - lib/generators/validation_tracker/templates/install.rb
36
+ - lib/validation_tracker.rb
37
+ - lib/validation_tracker/attempt.rb
38
+ - lib/validation_tracker/model.rb
39
+ - lib/validation_tracker/version.rb
40
+ homepage: http://rubygems.org/gems/validation_tracker
41
+ licenses: []
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.5.1
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Tracks Validation Issues on your forms
63
+ test_files: []