error_messages_container 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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +97 -0
- data/Rakefile +1 -0
- data/error_messages_container.gemspec +23 -0
- data/lib/error_messages_container.rb +81 -0
- data/lib/error_messages_container/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e05171e01ca57b5296f1b56a8288e4f4ae01fbe
|
4
|
+
data.tar.gz: 4b9d2e88cbd3e9dddd403d3a279483a5635a6cff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 124d68b592b8b9047d1cf4998f0ac6a7465b4bc3854809b21c4ac652bf8bb6f1a1887874a85a605586c2d8d0732395a00c49cde29e7e068ed12addbdf092241f
|
7
|
+
data.tar.gz: eccfc0f78cc39adec637d534d5ccefeb9f2bccfe27529f21326bdfcd766e60e758ddc480cc9a285a2394ac674b05928edffe6cb75390564617f58d460bf25fc7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ivan Zabrovskiy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# ErrorMessagesContainer
|
2
|
+
|
3
|
+
This is simple container for storage and grouping error messages
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'error_messages_container'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install error_messages_container
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Initialize instance
|
22
|
+
|
23
|
+
errors_container = ErrorMessagesContainer::ErrorMessages.new('Base application errors')
|
24
|
+
|
25
|
+
### Work with groups
|
26
|
+
|
27
|
+
Adding new group
|
28
|
+
|
29
|
+
errors_container.add_group(:horrible_errors, 'My horrible errors')
|
30
|
+
|
31
|
+
Get group name
|
32
|
+
|
33
|
+
errors_container.name_for_group(:horrible_errors) # => 'My horrible errors'
|
34
|
+
|
35
|
+
Get all groups type
|
36
|
+
|
37
|
+
errors_container.all_group_types # => [:base, :horrible_errors]
|
38
|
+
|
39
|
+
### Adding errors to group
|
40
|
+
|
41
|
+
Add errors to base section
|
42
|
+
|
43
|
+
errors_container.add('we catch simple error')
|
44
|
+
|
45
|
+
Add error to new section
|
46
|
+
|
47
|
+
errors_container.add('occurred another error', :horrible_errors)
|
48
|
+
|
49
|
+
Add multiple messages
|
50
|
+
|
51
|
+
errors_container.add(%w(many small messages), :horrible_errors)
|
52
|
+
|
53
|
+
### Reading errors group info
|
54
|
+
|
55
|
+
For example you can use this on you view
|
56
|
+
|
57
|
+
%ul
|
58
|
+
- @errors_container.all_messages.each do |group_name, messages|
|
59
|
+
%li
|
60
|
+
.error-type
|
61
|
+
= @errors_container.name_for_group(group_name)
|
62
|
+
%ul
|
63
|
+
- messages.each do |message|
|
64
|
+
%li
|
65
|
+
= message
|
66
|
+
|
67
|
+
Get all messages for group
|
68
|
+
|
69
|
+
errors_container.messages_for_group(group_name)
|
70
|
+
|
71
|
+
Get Hash with all messages, except empty groups
|
72
|
+
|
73
|
+
errors_container.all_messages
|
74
|
+
|
75
|
+
### Helper methods
|
76
|
+
|
77
|
+
Here is 'blank?' and 'present?' for errors_container instance
|
78
|
+
|
79
|
+
### Helper methods for group
|
80
|
+
|
81
|
+
If you add group
|
82
|
+
|
83
|
+
errors_container.add_group(:example, 'My group for example')
|
84
|
+
errors_container.add('Test message', :example)
|
85
|
+
|
86
|
+
You automatically has follow methods
|
87
|
+
|
88
|
+
errors_container.example_group_name # => 'My group for example'
|
89
|
+
errors_container.example_group_messages # => ['Test message']
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
1. Fork it ( http://github.com/Loriowar/error_messages_container/fork )
|
94
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
96
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
97
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'error_messages_container/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "error_messages_container"
|
8
|
+
spec.version = ErrorMessagesContainer::VERSION
|
9
|
+
spec.authors = ["Ivan Zabrovskiy"]
|
10
|
+
spec.email = ["loriowar@gmail.com"]
|
11
|
+
spec.summary = %q{Simple error messages container}
|
12
|
+
spec.description = %q{Simple container for storage and grouping error messages}
|
13
|
+
spec.homepage = "https://github.com/Loriowar/error_messages_container"
|
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_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "error_messages_container/version"
|
2
|
+
|
3
|
+
module ErrorMessagesContainer
|
4
|
+
class ErrorMessages
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# stub
|
8
|
+
end
|
9
|
+
|
10
|
+
# available args:
|
11
|
+
# base_name - name of the default section
|
12
|
+
# error_messages - Array or String with error message(s) for base section
|
13
|
+
def initialize(args = {})
|
14
|
+
@error_messages = {base: []}
|
15
|
+
@group_names = {base: args[:base_name] || 'base_section'}
|
16
|
+
define_group_reader(:base)
|
17
|
+
self.add(args[:error_messages]) if args.has_key?(:error_messages)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add(error, group_name = :base)
|
21
|
+
if error.is_a?(String)
|
22
|
+
@error_messages[group_name.to_sym] << error
|
23
|
+
elsif error.is_a?(Array)
|
24
|
+
@error_messages[group_name.to_sym] += error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_group(group_name, group_description)
|
29
|
+
if @error_messages[group_name.to_sym].blank? && @group_names[group_name.to_sym].blank?
|
30
|
+
@error_messages[group_name.to_sym] = []
|
31
|
+
@group_names[group_name.to_sym] = group_description
|
32
|
+
define_group_reader(group_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def all_messages
|
37
|
+
@error_messages.reject{|_, messages| messages.blank?}
|
38
|
+
end
|
39
|
+
|
40
|
+
def messages_for_group(group_name)
|
41
|
+
@error_messages[group_name.to_sym]
|
42
|
+
end
|
43
|
+
|
44
|
+
def all_group_names
|
45
|
+
@group_names
|
46
|
+
end
|
47
|
+
|
48
|
+
def name_for_group(group_name)
|
49
|
+
@group_names[group_name.to_sym]
|
50
|
+
end
|
51
|
+
|
52
|
+
def all_group_types
|
53
|
+
@error_messages.keys
|
54
|
+
end
|
55
|
+
|
56
|
+
def blank?
|
57
|
+
@error_messages.values.collect(&:blank?).all?
|
58
|
+
end
|
59
|
+
|
60
|
+
def present?
|
61
|
+
!blank?
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# дефайн методов для удобного получения ошибок в группе и названия группы
|
67
|
+
# define methods for comfortable access to error group and group name
|
68
|
+
def define_group_reader(group_name)
|
69
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
70
|
+
def #{group_name}_group_messages # def base_group_messages
|
71
|
+
@error_messages[:#{group_name}] # @error_messages[:base]
|
72
|
+
end # end
|
73
|
+
|
74
|
+
def #{group_name}_group_name # def base_group_name
|
75
|
+
@group_names[:#{group_name}] # @group_names[:base]
|
76
|
+
end # end
|
77
|
+
EOT
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: error_messages_container
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Zabrovskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Simple container for storage and grouping error messages
|
42
|
+
email:
|
43
|
+
- loriowar@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- error_messages_container.gemspec
|
54
|
+
- lib/error_messages_container.rb
|
55
|
+
- lib/error_messages_container/version.rb
|
56
|
+
homepage: https://github.com/Loriowar/error_messages_container
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Simple error messages container
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|