whiny_validation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +2 -0
- data/lib/whiny_validation/configuration.rb +17 -0
- data/lib/whiny_validation/version.rb +3 -0
- data/lib/whiny_validation.rb +36 -0
- data/whiny_validation.gemspec +22 -0
- data/whiny_validation.gif +0 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74c55d1e87705a2da008e8b9347d7d427ddf97d2
|
4
|
+
data.tar.gz: e7c710cfbfdce61e0d8fdcd7a3e5b858a7d30ef9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 750bfacfe3c487d6301683f6da65333ae34dcbe22434fab4327d7bc7baec8e75184803296fa8cedfab2dca932227ed219980d827140375a47638b25316c88863
|
7
|
+
data.tar.gz: 1bece7fc4e32cd2bc3299643cf8f258256ca0b94a33904cd439b506d7eb195901ac7889fe1306981209c04a8af8c6e8a60bcd08b1733504bdd3d4238d0d7b725
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brian Morearty
|
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,72 @@
|
|
1
|
+
# WhinyValidation
|
2
|
+
|
3
|
+
Your spec fails and you don't know why. You look at the log,
|
4
|
+
but it doesn't give you any clues. You waste 15 minutes trying
|
5
|
+
to figure it out.
|
6
|
+
|
7
|
+
WhinyValidation to the rescue.
|
8
|
+
|
9
|
+
When an ActiveRecord model won't save because it's invalid,
|
10
|
+
this gem writes the validation error messages to the log.
|
11
|
+
|
12
|
+
The log shows all the attributes of the ActiveRecord object
|
13
|
+
that failed, along with the error message.
|
14
|
+
|
15
|
+
Validation errors are shown in an attractive yellow, which
|
16
|
+
stands out nicely if your terminal background is dark.
|
17
|
+
|
18
|
+
It can be useful in development and especially in test mode,
|
19
|
+
to understand why a model didn't save.
|
20
|
+
|
21
|
+
![Whiny Validation](whiny_validation.gif)
|
22
|
+
|
23
|
+
## Compatibility
|
24
|
+
|
25
|
+
Ruby 1.9.3 and above.
|
26
|
+
|
27
|
+
Rails 3.2 and above.
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
gem 'whiny_validation'
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install whiny_validation
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
When a model didn't save but you expected it to save, look in the
|
46
|
+
log for "Validation failed."
|
47
|
+
|
48
|
+
## Configuration
|
49
|
+
|
50
|
+
By default, the gem uses debug-level logging, so any Rails environment
|
51
|
+
with debug-level logging will include the whiny validation messages.
|
52
|
+
|
53
|
+
You can change the log level like so:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# config/initializers/whiny_validation.rb
|
57
|
+
WhinyValidation.configure do |config|
|
58
|
+
config.log_level = :info
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Tests
|
63
|
+
|
64
|
+
Quit your whining.
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module WhinyValidation
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
yield configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
class Configuration
|
11
|
+
attr_accessor :log_level
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@log_level = :debug
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "whiny_validation/version"
|
2
|
+
require "whiny_validation/configuration"
|
3
|
+
|
4
|
+
module WhinyValidation
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
after_validation :whiny_validation, :if => proc { |model| model.errors.present? }
|
9
|
+
end
|
10
|
+
|
11
|
+
def whiny_validation
|
12
|
+
ActiveSupport::Notifications.instrument("validation_failed.whiny_validation",
|
13
|
+
:object => self,
|
14
|
+
:error_messages => errors.full_messages)
|
15
|
+
end
|
16
|
+
|
17
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
18
|
+
def validation_failed(event)
|
19
|
+
send(WhinyValidation.configuration.log_level) do
|
20
|
+
name = color("Validation failed", YELLOW, true)
|
21
|
+
object = event.payload[:object]
|
22
|
+
error_messages = color(event.payload[:error_messages].map{|message|" => #{message}"}.join("\n"), YELLOW)
|
23
|
+
|
24
|
+
" #{name} #{object.inspect}\n#{error_messages}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
WhinyValidation::LogSubscriber.attach_to :whiny_validation
|
30
|
+
end
|
31
|
+
|
32
|
+
module ActiveRecord
|
33
|
+
class Base
|
34
|
+
include WhinyValidation
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/whiny_validation/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Morearty"]
|
6
|
+
gem.email = ["brian@morearty.org"]
|
7
|
+
gem.description = %q{When an ActiveRecord model won't save because it's invalid, this gem writes the validation error messages to the log.}
|
8
|
+
gem.summary = %q{Write ActiveRecord validation error messages to the log}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "whiny_validation"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = WhinyValidation::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'activesupport'
|
19
|
+
gem.add_dependency 'activerecord'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whiny_validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Morearty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: When an ActiveRecord model won't save because it's invalid, this gem
|
56
|
+
writes the validation error messages to the log.
|
57
|
+
email:
|
58
|
+
- brian@morearty.org
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/whiny_validation.rb
|
69
|
+
- lib/whiny_validation/configuration.rb
|
70
|
+
- lib/whiny_validation/version.rb
|
71
|
+
- whiny_validation.gemspec
|
72
|
+
- whiny_validation.gif
|
73
|
+
homepage: ''
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Write ActiveRecord validation error messages to the log
|
96
|
+
test_files: []
|