activemodel_detailed_errors 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb4f22b2b56ce86b16f06ff8871b7ef140e698de
4
+ data.tar.gz: 6b68be7b32d973e328073078c1e4480cec6fa3fc
5
+ SHA512:
6
+ metadata.gz: f07b925948bb1ecd42b83779c8914549bf5dcfa5717591f6418a6d407cd641acf8ab3c8b618ac2aa6732ce916d177908bc844a23f29fa423355e14ec44b43884
7
+ data.tar.gz: bc08d459f7652634ce0f65094ecb3e5294ede537902d95bc26427ca880334bb679c0cf79aa4509d1824fc7c2dce6cecffa02e08998ea9accf1bccb30d80befb4
@@ -0,0 +1,20 @@
1
+ Copyright 2015 juliogarciag
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.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ require "activemodel_detailed_errors/engine"
2
+
3
+ module ActivemodelDetailedErrors
4
+ end
@@ -0,0 +1,9 @@
1
+ module ActivemodelDetailedErrors
2
+ class Engine < ::Rails::Engine
3
+ initializer "include .details method in ActiveAdmin" do |app|
4
+ unless ActiveModel::Errors.methods.include?(:details)
5
+ require "activemodel_detailed_errors/load_error_details_support"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,54 @@
1
+ module ActiveModel
2
+ class Errors
3
+ MESSAGE_OPTIONS = [:message]
4
+
5
+ attr_accessor :details
6
+
7
+ def initialize(base)
8
+ @base = base
9
+ @messages = Hash.new { |messages, attribute| messages[attribute] = [] }
10
+ @details = Hash.new { |details, attribute| details[attribute] = [] }
11
+ end
12
+
13
+ def initialize_dup(other) # :nodoc:
14
+ @messages = other.messages.dup
15
+ @details = other.details.deep_dup
16
+ super
17
+ end
18
+
19
+ def clear
20
+ messages.clear
21
+ details.clear
22
+ end
23
+
24
+ def delete
25
+ messages.delete(key)
26
+ details.delete(key)
27
+ end
28
+
29
+ def add(attribute, message = :invalid, options = {})
30
+ message = message.call if message.respond_to?(:call)
31
+ detail = normalize_detail(attribute, message, options)
32
+ message = normalize_message(attribute, message, options)
33
+ if exception = options[:strict]
34
+ exception = ActiveModel::StrictValidationFailed if exception == true
35
+ raise exception, full_message(attribute, message)
36
+ end
37
+
38
+ details[attribute.to_sym] << detail
39
+ self[attribute] << message
40
+ end
41
+
42
+ def added?(attribute, message = :invalid, options = {})
43
+ message = message.call if message.respond_to?(:call)
44
+ message = normalize_message(attribute, message, options)
45
+ self[attribute].include? message
46
+ end
47
+
48
+ private
49
+
50
+ def normalize_detail(attribute, message, options)
51
+ { error: message }.merge(options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS))
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module ActivemodelDetailedErrors
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activemodel_detailed_errors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - juliogarciag
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-14 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: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ description: errors.details from Rails 5 for Rails 4 people.
28
+ email:
29
+ - julioggonz@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - lib/activemodel_detailed_errors.rb
37
+ - lib/activemodel_detailed_errors/engine.rb
38
+ - lib/activemodel_detailed_errors/load_error_details_support.rb
39
+ - lib/activemodel_detailed_errors/version.rb
40
+ homepage: https://github.com/platanus/activemodel_detailed_errors
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.4.7
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: errors.details from Rails 5 for Rails 4 people.
64
+ test_files: []