error_merger 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f6a3809f25d08b76e1b6008ffa9a0213d7cc5a4
4
+ data.tar.gz: 26204505d21f20d99be522de7c1288b1dc1820f5
5
+ SHA512:
6
+ metadata.gz: 799aa0809e3434a3b174edff7e1e2092f6e132dd714767c8dab553dc5da75f0fd7dbae5e187b6aa498549520f2e33be8f78201bea5038887e8d50378a60cd4ec
7
+ data.tar.gz: ad3a65b86614c8d9ce6699b8c51e9b3d309a6672b94e9808069c65b2abdb63799b3e5f4f6a2dc7e83e47f62017c9f3fa65888b56319f0bd0f1b6c8b0bd26b198
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in error_merger.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 thomas morgan
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,45 @@
1
+ # ErrorMerger
2
+
3
+ Adds a .merge method to ActiveModel-compliant models.
4
+
5
+ Allows the merging/consolidation of errors on multiple models to make it easy
6
+ to pass into some kind of error renderer.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'error_merger'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install error_merger
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ @user = User.new user_params
26
+ @account = Account.new account_params
27
+ @account.errors.merge @user
28
+
29
+ @account.errors.to_sentence # => will include errors for both Account and User
30
+ ```
31
+
32
+ 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".
33
+
34
+ The default behavior is the equivalent to: `@account.errors.merge @user, 'User: '`
35
+
36
+ To skip prefixing, pass an empty string: `''`.
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'error_merger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'error_merger'
8
+ spec.version = ErrorMerger::VERSION
9
+ spec.authors = ['thomas morgan']
10
+ spec.email = ['tm@iprog.com']
11
+ spec.description = %q{Enables combining error messages on ActiveModel-compliant models.}
12
+ spec.summary = %q{Enables combining error messages on ActiveModel-compliant models}
13
+ spec.homepage = 'https://github.com/zarqman/error_merger'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'activemodel', '~> 4.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,20 @@
1
+ module ErrorMerger
2
+ # merges an association's Errors set into the current set
3
+ # eg: @user.errors.merge @account
4
+ # @user.errors.merge @account, "Account ##{@account.id}: "
5
+ def merge(association, prefix=nil)
6
+ if association.errors.respond_to? :full_message
7
+ prefix ||= "#{association.class.model_name.human}: "
8
+ association.errors.each do |attr, error|
9
+ add :base, "#{prefix}#{association.errors.full_message(attr, error)}"
10
+ end
11
+ else
12
+ association.errors.each do |error|
13
+ add :base, error
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ ActiveModel::Errors.send :include, ErrorMerger
@@ -0,0 +1,3 @@
1
+ module ErrorMerger
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'error_merger/version'
2
+ require 'error_merger/error_merger'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error_merger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thomas morgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
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: Enables combining error messages on ActiveModel-compliant models.
56
+ email:
57
+ - tm@iprog.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - error_merger.gemspec
68
+ - lib/error_merger.rb
69
+ - lib/error_merger/error_merger.rb
70
+ - lib/error_merger/version.rb
71
+ homepage: https://github.com/zarqman/error_merger
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Enables combining error messages on ActiveModel-compliant models
95
+ test_files: []