errors_full_details 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/lib/errors_full_details/core_ext.rb +14 -0
- data/lib/errors_full_details/railtie.rb +4 -0
- data/lib/errors_full_details/version.rb +3 -0
- data/lib/errors_full_details.rb +5 -0
- data/lib/tasks/errors_full_details_tasks.rake +4 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 759a4c27d265a5f1a8dc197e25c23246d44c8ef8
|
4
|
+
data.tar.gz: cc03e8dd856404c6979afbc911666d3051b25240
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d4f51fa050b5c0eb1015b963a9e98d632b73856efced2966af0fb673abd73bb00e23239d45ab3a02cec4904398092efe8a62e30b9ab5ccc4f4cb9bfff43e4101
|
7
|
+
data.tar.gz: ec334492290a9c8dcdda3b1e9ee0c08358beb35c2fcd5f102cb651395cc9c759be0140d0952d5ed9cac68178d6fc1eee468a77c873006c2a3f27194648211d7e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Umar Al-Kfaween
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# ErrorsFullDetails
|
2
|
+
Adds a new method to ActiveModel::Errors to display messages with codes using details.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Add errors with codes to an object:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Person < ApplicationRecord
|
9
|
+
validate :username_is_cool
|
10
|
+
validate :title_is_looking_good
|
11
|
+
validate :default_code
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def username_is_cool
|
16
|
+
errors.add(:username, 'is not cool', code: 15)
|
17
|
+
end
|
18
|
+
|
19
|
+
def title_is_looking_good
|
20
|
+
errors.add(:title, 'is not looking good', code: '210')
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_code
|
24
|
+
errors.add(:base, 'This error has a default code')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
Call `object.errors.full_details` to generate an array of error messages and codes:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
[
|
33
|
+
{
|
34
|
+
message: "Username is not cool",
|
35
|
+
code: "15"
|
36
|
+
},
|
37
|
+
{
|
38
|
+
message: "Title is not looking good",
|
39
|
+
code: "210"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
message: "This error has a default code",
|
43
|
+
code: "default"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
```
|
47
|
+
|
48
|
+
Errors added without an error code will return `'0'` as a default error code.
|
49
|
+
|
50
|
+
## Installation
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem "errors_full_details", git: "https://github.com/umar221b/errors_full_details.git"
|
55
|
+
```
|
56
|
+
|
57
|
+
And then execute:
|
58
|
+
```bash
|
59
|
+
$ bundle
|
60
|
+
```
|
61
|
+
|
62
|
+
## License
|
63
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ErrorsFullDetails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
class Errors
|
3
|
+
def full_details
|
4
|
+
details.each_with_object([]) do |(attr, error_arr), errors|
|
5
|
+
attr_name = attr.to_s.humanize
|
6
|
+
error_arr.each do |error|
|
7
|
+
message = (attr == :base ? '' : "#{attr_name} ") + error[:error]
|
8
|
+
code = error.key?(:code) ? error[:code].to_s : '0'
|
9
|
+
errors << { message: message, code: code }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errors_full_details
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Umar Al-Kfaween
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-28 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: 5.2.2
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.2.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.2.2
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.2.2.1
|
33
|
+
description: ErrorsFullDetails extends ActiveModel::Errors to allow adding error codes
|
34
|
+
to error messages
|
35
|
+
email:
|
36
|
+
- omar.ka923@gmail.com
|
37
|
+
executables: []
|
38
|
+
extensions: []
|
39
|
+
extra_rdoc_files: []
|
40
|
+
files:
|
41
|
+
- MIT-LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/errors_full_details.rb
|
45
|
+
- lib/errors_full_details/core_ext.rb
|
46
|
+
- lib/errors_full_details/railtie.rb
|
47
|
+
- lib/errors_full_details/version.rb
|
48
|
+
- lib/tasks/errors_full_details_tasks.rake
|
49
|
+
homepage: https://github.com/umar221b/errors_full_details
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata:
|
53
|
+
allowed_push_host: https://rubygems.org
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.6.11
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: ErrorsFullDetails extends ActiveModel::Errors to allow adding error codes
|
74
|
+
to error messages
|
75
|
+
test_files: []
|