validb 1.1.3 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b848b12eed8009be429914ef6310dc3dbddae8d
4
- data.tar.gz: 78ed0cdb95648b0611e0e50fe8043772d3868b67
3
+ metadata.gz: 37dd5d6147cb53a3dfb53c855f2a55d0cf647537
4
+ data.tar.gz: 5be261954815e7d0c9fe79bbbf5e127c239c8a3a
5
5
  SHA512:
6
- metadata.gz: 4c5117c74c947b2447eedb3f2b67dcbab81c7eedfc31d6376ee312bb71a34d0dcc25e9579df4f3e274139f6aeaa29113e9c1087dd9df137f17390a6ff2f9840e
7
- data.tar.gz: 5ae04ab9bb93db6f1757f4962bbda4fcc04682b7e5bfc0d43346fb16e386d43c6965ae19c3ea323f55d44d7f22b1703a3e6af4cf9a2b8d7d6d9813bb15eed889
6
+ metadata.gz: fcd4b986c94eefb884ba2f8fc464370547cf593ea286ab8de0e55427c7ca282d82eed62203e6574932776a624f6069b2f563358f95858d48b949beb434bdcd9a
7
+ data.tar.gz: a442ed7e407b7f86196387f745951010cad183461b05292c8b4445651b3c7e731ec29e58c9937584aff828e7c3db3e1177a2fe7b2d52d239b62ae629af369ebe
@@ -1,4 +1,9 @@
1
- ## 1.1.3, released 2013-04-21
1
+ ## 1.2.0, released 2013-04-04
2
+ * FileSystem logger is now default
3
+ * Print an 'x' for each record validation failure when using FileSystem logger
4
+ * Output number of seconds for task completion
5
+
6
+ ## 1.1.3, released 2013-04-01
2
7
  * Remove extra period in output to remove batch confusion
3
8
  * Set default batch size to 1000
4
9
 
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/validb.png)](https://rubygems.org/gems/validb)
4
4
  [![Dependency Status](https://gemnasium.com/jgeiger/validb.png)](https://gemnasium.com/jgeiger/validb)
5
5
  [![Build Status](https://travis-ci.org/jgeiger/validb.png)](https://travis-ci.org/jgeiger/validb)
6
+ [![Code Climate](https://codeclimate.com/github/jgeiger/validb.png)](https://codeclimate.com/github/jgeiger/validb)
6
7
 
7
8
  ## Description
8
9
 
@@ -24,7 +25,7 @@ Check your database for invalid models.
24
25
  rake validb:validate models="Model,Model"
25
26
 
26
27
  ### Specific logger
27
- rake validb:validate logger="Validb::ConsoleLogger"
28
+ rake validb:validate logger="Validb::Logger::Console"
28
29
 
29
30
  ### Generate config file in config/validb.json
30
31
  rake validb:generate_config
@@ -2,7 +2,7 @@ namespace :validb do
2
2
  desc "Check DB for invalid records"
3
3
  task :validate => :environment do
4
4
  models = ENV["models"] || ""
5
- logger_class = ENV["logger"] || "Validb::ConsoleLogger"
5
+ logger_class = ENV["logger"] || "Validb::Logger::FileSystem"
6
6
  filename = ENV["config"] || default_configuration_file
7
7
 
8
8
  # force all models to load so we can find them
@@ -13,8 +13,12 @@ namespace :validb do
13
13
  finder = Validb::Finder.new(params, models)
14
14
 
15
15
  logger = logger_class.constantize.new
16
+ logger.prepare
17
+
18
+ started_at = Time.now
16
19
  checker = Validb::Checker.new(params, logger)
17
20
  checker.check(finder.models)
21
+ puts "\nFinished in #{Time.now-started_at} seconds"
18
22
  end
19
23
 
20
24
  desc "Generate config/validb.json"
@@ -6,7 +6,6 @@ require 'validb/version'
6
6
  module Validb
7
7
  require 'validb/railtie' if defined?(Rails)
8
8
  autoload :Configuration, 'validb/configuration'
9
- autoload :ConsoleLogger, 'validb/console_logger'
10
9
  autoload :Checker, 'validb/checker'
11
10
  autoload :Finder, 'validb/finder'
12
11
  autoload :ModelFilterer, 'validb/model_filterer'
@@ -14,4 +13,9 @@ module Validb
14
13
  autoload :Batcher, 'validb/batcher'
15
14
  autoload :RecordValidator, 'validb/record_validator'
16
15
  autoload :Parameters, 'validb/parameters'
16
+ module Logger
17
+ autoload :Base, 'validb/logger/base'
18
+ autoload :FileSystem, 'validb/logger/file_system'
19
+ autoload :Console, 'validb/logger/console'
20
+ end
17
21
  end
@@ -0,0 +1,11 @@
1
+ module Validb
2
+ module Logger
3
+ class Base
4
+ def prepare
5
+ end
6
+
7
+ def out(record_hash)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Validb
2
+ module Logger
3
+ class Console < Base
4
+ def out(record_hash)
5
+ $stdout.puts "\n#{record_hash[:model]}:#{record_hash[:id]} - #{record_hash[:error_messages]}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Validb
2
+ module Logger
3
+ class FileSystem < Base
4
+ def prepare
5
+ File.delete(filename) if File.exists?(filename)
6
+ $stdout.puts("Writing output to #{filename}")
7
+ end
8
+
9
+ def out(record_hash)
10
+ File.open(filename, "ab+") do |file|
11
+ file.puts("#{record_hash[:model]}:#{record_hash[:id]} - #{record_hash[:error_messages]}")
12
+ end
13
+ $stdout.print("x")
14
+ end
15
+
16
+ private
17
+
18
+ def filename
19
+ @filename ||= defined?(Rails) ? Rails.root.join('log', 'validb.log') : "validb.log"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Validb
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Validb::ConsoleLogger do
3
+ describe Validb::Logger::Console do
4
4
  describe "#out" do
5
5
  it "prints the hash output" do
6
6
  hash = { model: Blog, id: 1, error_messages: "Error message" }
7
7
 
8
- console_logger = Validb::ConsoleLogger.new
8
+ console_logger = Validb::Logger::Console.new
9
9
  $stdout.should_receive(:puts).with("\nBlog:1 - Error message")
10
10
  console_logger.out(hash)
11
11
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validb::Logger::FileSystem do
4
+ describe "#prepare" do
5
+ context "when the file exists" do
6
+ it "deletes the file" do
7
+ File.should_receive(:exists?).with("validb.log").and_return(true)
8
+ File.should_receive(:delete).with("validb.log")
9
+
10
+ $stdout.should_receive(:puts).with("Writing output to validb.log")
11
+
12
+ file_logger = Validb::Logger::FileSystem.new
13
+ file_logger.prepare
14
+ end
15
+ end
16
+
17
+ context "when the file does not exist" do
18
+ it "does nothing" do
19
+ File.should_receive(:exists?).with("validb.log").and_return(false)
20
+ File.should_not_receive(:delete)
21
+
22
+ $stdout.should_receive(:puts).with("Writing output to validb.log")
23
+
24
+ file_logger = Validb::Logger::FileSystem.new
25
+ file_logger.prepare
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#out" do
31
+ it "writes the hash output to a file and prints an X" do
32
+ file = double('file')
33
+ File.should_receive(:open).with("validb.log", "ab+").and_yield(file)
34
+ file.should_receive(:puts).with("Blog:1 - Error message")
35
+
36
+ $stdout.should_receive(:print).with("x")
37
+
38
+ hash = { model: Blog, id: 1, error_messages: "Error message" }
39
+ file_logger = Validb::Logger::FileSystem.new
40
+ file_logger.out(hash)
41
+ end
42
+ end
43
+ end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe Validb do
4
4
  it "returns the version" do
5
- Validb::VERSION.should == "1.1.3"
5
+ Validb::VERSION.should == "1.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joey Geiger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-01 00:00:00.000000000 Z
11
+ date: 2013-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -41,8 +41,10 @@ files:
41
41
  - lib/validb/batcher.rb
42
42
  - lib/validb/checker.rb
43
43
  - lib/validb/configuration.rb
44
- - lib/validb/console_logger.rb
45
44
  - lib/validb/finder.rb
45
+ - lib/validb/logger/base.rb
46
+ - lib/validb/logger/console.rb
47
+ - lib/validb/logger/file_system.rb
46
48
  - lib/validb/model_filterer.rb
47
49
  - lib/validb/model_validator.rb
48
50
  - lib/validb/parameters.rb
@@ -54,8 +56,9 @@ files:
54
56
  - spec/validb/batcher_spec.rb
55
57
  - spec/validb/checker_spec.rb
56
58
  - spec/validb/configuration_spec.rb
57
- - spec/validb/console_logger_spec.rb
58
59
  - spec/validb/finder_spec.rb
60
+ - spec/validb/logger/console_spec.rb
61
+ - spec/validb/logger/file_system_spec.rb
59
62
  - spec/validb/model_filterer_spec.rb
60
63
  - spec/validb/model_validator_spec.rb
61
64
  - spec/validb/record_validator_spec.rb
@@ -1,8 +0,0 @@
1
- module Validb
2
- class ConsoleLogger
3
-
4
- def out(record_hash)
5
- $stdout.puts "\n#{record_hash[:model]}:#{record_hash[:id]} - #{record_hash[:error_messages]}"
6
- end
7
- end
8
- end