error_merger 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +12 -2
- data/error_merger.gemspec +2 -2
- data/lib/error_merger/error_merger.rb +10 -0
- data/lib/error_merger/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdfba3e2cb6c55f351c7ee4b7b0c5883cce24812
|
4
|
+
data.tar.gz: f7b4196f44499e44d289eef42c838925f1ce98db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d83cd3309db5412fbde975ac1efc1d0b86b098393511a08a5361b887c688c06b5fefa9c98be4b1b7272115050ae390fc1263c3b66845e38392839c33689c439
|
7
|
+
data.tar.gz: 4dc60344e5e03b4cedce1c328e34c3c11458f95ab89a30ecb709e37d5edc9dd5870f99c668eae2eb7b20480edbc3daea484d35294836eb10692a19ca450e8cec
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# ErrorMerger
|
2
2
|
|
3
|
-
Adds a
|
3
|
+
Adds a #merge method to ActiveModel-compliant models.
|
4
4
|
|
5
5
|
Allows the merging/consolidation of errors on multiple models to make it easy
|
6
6
|
to pass into some kind of error renderer.
|
7
7
|
|
8
|
+
Also adds #full_sentence and #full_sentences methods, with are comparable to
|
9
|
+
\#full_message and #full_messages respectively, except they ensure each error
|
10
|
+
message always ends with a period.
|
11
|
+
|
8
12
|
## Installation
|
9
13
|
|
10
14
|
Add this line to your application's Gemfile:
|
@@ -19,14 +23,20 @@ Or install it yourself as:
|
|
19
23
|
|
20
24
|
$ gem install error_merger
|
21
25
|
|
26
|
+
|
22
27
|
## Usage
|
23
28
|
|
24
29
|
```
|
25
30
|
@user = User.new user_params
|
31
|
+
@user.valid? # => false
|
26
32
|
@account = Account.new account_params
|
33
|
+
@account.valid? # => false
|
27
34
|
@account.errors.merge @user
|
28
35
|
|
29
|
-
@account.errors.
|
36
|
+
@account.errors.full_messages # => will include errors for both Account and User
|
37
|
+
|
38
|
+
@user.errors.full_messages # => ["Username can't be blank"]
|
39
|
+
@user.errors.full_sentences # => ["Username can't be blank."]
|
30
40
|
```
|
31
41
|
|
32
42
|
By default merged errors are prefixed with the model name. In the above example, an error on User might look like: "User: First name must not be blank".
|
data/error_merger.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ErrorMerger::VERSION
|
9
9
|
spec.authors = ['thomas morgan']
|
10
10
|
spec.email = ['tm@iprog.com']
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.description = %q{Enhances the Error class on ActiveModel-compliant models with merge() and full_sentences() methods.}
|
12
|
+
spec.summary = %q{Enhances the Error class on ActiveModel-compliant models}
|
13
13
|
spec.homepage = 'https://github.com/zarqman/error_merger'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module ErrorMerger
|
2
|
+
|
2
3
|
# merges an association's Errors set into the current set
|
3
4
|
# eg: @user.errors.merge @account
|
4
5
|
# @user.errors.merge @account, "Account ##{@account.id}: "
|
@@ -15,6 +16,15 @@ module ErrorMerger
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
19
|
+
def full_sentences
|
20
|
+
map{ |attr, m| full_sentence(attr, m) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_sentence(attribute, message)
|
24
|
+
m = full_message(attribute, message)
|
25
|
+
m.ends_with?('.') ? m : "#{m}."
|
26
|
+
end
|
27
|
+
|
18
28
|
end
|
19
29
|
|
20
30
|
ActiveModel::Errors.send :include, ErrorMerger
|
data/lib/error_merger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: error_merger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: Enhances the Error class on ActiveModel-compliant models with merge()
|
56
|
+
and full_sentences() methods.
|
56
57
|
email:
|
57
58
|
- tm@iprog.com
|
58
59
|
executables: []
|
@@ -91,5 +92,5 @@ rubyforge_project:
|
|
91
92
|
rubygems_version: 2.0.6
|
92
93
|
signing_key:
|
93
94
|
specification_version: 4
|
94
|
-
summary:
|
95
|
+
summary: Enhances the Error class on ActiveModel-compliant models
|
95
96
|
test_files: []
|