exclusive-error-message 1.0.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: fa3de337d955da7bdd0f45402f35cb22c77974c9
4
+ data.tar.gz: 160fe8dc77bdaa844dbc1b48de9f478d2a5eb740
5
+ SHA512:
6
+ metadata.gz: 043a3a5b0f30fd478c78aee7409d352b7a2e245611da5def98fbe96cd49b54b9a2cf925440e030c4a55045116d13c3b678162aee25196993c49a5b4587165d7d
7
+ data.tar.gz: 9172ddc7ee42304d014eb8cffe438a5f6e9ca14a6d66fd83546abfe3147f46d0016b159d85f8c184923d0426139d3f27158543c730278b618f30bfb9eb7534a3
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ .ruby-version
4
+ pkg/
5
+ tmp/
6
+ /.idea/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.4.0
5
+
6
+ cache: bundler
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ ## Allows to specify 100% exclusive message for any `ActiveModel` validation error.
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/exclusive-error-message.svg)](https://badge.fury.io/rb/exclusive-error-message)
4
+
5
+ ## Usage
6
+ **Summary**
7
+
8
+ Prefix any error message with `_` and it will become full message omitting `I18n(:'errors.format', ...)` processing.
9
+
10
+ **Before**
11
+ ```ruby
12
+ class Post < ActiveRecord::Base
13
+ validates :title, presence: { message: "Sorry, but title can't be empty" }
14
+ end
15
+
16
+ post = Post.new
17
+ post.validate
18
+
19
+ # Get full messages for errors:
20
+ post.errors.to_hash(true) # => { title: "Title: Sorry, but title can't be empty" }
21
+ ```
22
+
23
+ **After**
24
+ ```ruby
25
+ class Post < ActiveRecord::Base
26
+ validates :title, presence: { message: "_Sorry, but title can't be empty" }
27
+ end
28
+
29
+ post = Post.new
30
+ post.validate
31
+
32
+ # Get full messages for errors:
33
+ post.errors.to_hash(true) # => { title: "Sorry, but title can't be empty" }
34
+ ```
35
+
36
+ **Usage in localizations**
37
+ ```yaml
38
+ en:
39
+ activerecord:
40
+ errors:
41
+ models:
42
+ post:
43
+ attributes:
44
+ title:
45
+ blank: _Sorry, but title can't be empty
46
+ ```
47
+
48
+ **Add error manually**
49
+ ```ruby
50
+ post = Post.new
51
+ errors = post.errors
52
+
53
+ errors.add(:title, "_Sorry, but title can't be empty")
54
+
55
+ # Get full messages for errors:
56
+ post.errors.to_hash(true) # => { title: "Sorry, but title can't be empty" }
57
+ ```
58
+
59
+ ## Installation
60
+ Add to your Gemfile:
61
+ ```ruby
62
+ gem 'exclusive-error-message', '~> 1.0'
63
+ ```
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path('../lib/exclusive-error-message/version', __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'exclusive-error-message'
8
+ s.version = ExclusiveErrorMessage::VERSION
9
+ s.author = 'Yaroslav Konoplov'
10
+ s.email = 'eahome00@gmail.com'
11
+ s.summary = '100% exclusive message for any ActiveModel validation error.'
12
+ s.description = '100% exclusive message for any ActiveModel validation error.'
13
+ s.homepage = 'https://github.com/yivo/exclusive-error-message'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.test_files = `git ls-files -z -- {test,spec,features}/*`.split("\x0")
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'activemodel', '>= 3.0', '< 6.0'
21
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module ExclusiveErrorMessage
5
+ module Extension
6
+ def full_message(attribute, message)
7
+ message.start_with?('_') ? message[1..-1] : super
8
+ end
9
+ end
10
+ end
11
+
12
+ require 'active_model/errors'
13
+
14
+ ActiveModel::Errors.prepend ExclusiveErrorMessage::Extension
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module ExclusiveErrorMessage
5
+ VERSION = '1.0.0'
6
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exclusive-error-message
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Konoplov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-28 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: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ description: 100% exclusive message for any ActiveModel validation error.
34
+ email: eahome00@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".gitignore"
40
+ - ".travis.yml"
41
+ - README.md
42
+ - exclusive-error-message.gemspec
43
+ - lib/exclusive-error-message.rb
44
+ - lib/exclusive-error-message/version.rb
45
+ homepage: https://github.com/yivo/exclusive-error-message
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.6.8
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: 100% exclusive message for any ActiveModel validation error.
69
+ test_files: []