active_model-better_errors 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +20 -0
- data/README.md +183 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/active_model-better_errors.gemspec +113 -0
- data/lib/active_model/better_errors.rb +15 -0
- data/lib/active_model/error_collecting.rb +49 -0
- data/lib/active_model/error_collecting/array_reporter.rb +9 -0
- data/lib/active_model/error_collecting/core_ext.rb +6 -0
- data/lib/active_model/error_collecting/emulation.rb +65 -0
- data/lib/active_model/error_collecting/error_collection.rb +86 -0
- data/lib/active_model/error_collecting/error_message.rb +88 -0
- data/lib/active_model/error_collecting/error_message_set.rb +35 -0
- data/lib/active_model/error_collecting/errors.rb +52 -0
- data/lib/active_model/error_collecting/hash_reporter.rb +9 -0
- data/lib/active_model/error_collecting/human_array_reporter.rb +9 -0
- data/lib/active_model/error_collecting/human_hash_reporter.rb +15 -0
- data/lib/active_model/error_collecting/human_message_formatter.rb +60 -0
- data/lib/active_model/error_collecting/human_message_reporter.rb +32 -0
- data/lib/active_model/error_collecting/machine_array_reporter.rb +19 -0
- data/lib/active_model/error_collecting/machine_hash_reporter.rb +22 -0
- data/lib/active_model/error_collecting/message_reporter.rb +17 -0
- data/lib/active_model/error_collecting/reporter.rb +14 -0
- data/spec/lib/active_model/better_errors_spec.rb +7 -0
- data/spec/lib/active_model/error_collecting/emulation_spec.rb +45 -0
- data/spec/lib/active_model/error_collecting/error_collection_spec.rb +205 -0
- data/spec/lib/active_model/error_collecting/error_message_set_spec.rb +96 -0
- data/spec/lib/active_model/error_collecting/error_message_spec.rb +293 -0
- data/spec/lib/active_model/error_collecting/errors_spec.rb +95 -0
- data/spec/lib/active_model/error_collecting/human_array_reporter_spec.rb +33 -0
- data/spec/lib/active_model/error_collecting/human_hash_reporter_spec.rb +32 -0
- data/spec/lib/active_model/error_collecting/human_message_formatter_spec.rb +22 -0
- data/spec/lib/active_model/error_collecting/human_message_reporter_spec.rb +61 -0
- data/spec/lib/active_model/error_collecting/machine_array_reporter_spec.rb +40 -0
- data/spec/lib/active_model/error_collecting/machine_hash_reporter_spec.rb +40 -0
- data/spec/lib/active_model/error_collecting_spec.rb +22 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/models.rb +28 -0
- data/test/integration.rb +10 -0
- metadata +274 -0
data/.document
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem "activemodel", "~> 3.0"
|
4
|
+
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "rake"
|
8
|
+
gem "rspec", "~> 2.12.0"
|
9
|
+
gem "pry"
|
10
|
+
gem "yard"
|
11
|
+
gem "rdoc"
|
12
|
+
gem "bundler"
|
13
|
+
gem "jeweler"
|
14
|
+
gem "simplecov"
|
15
|
+
gem 'bcrypt-ruby', '~> 3.0.0'
|
16
|
+
gem 'mocha', '>= 0.12.1'
|
17
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Aaron Qian
|
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,183 @@
|
|
1
|
+
# ActiveModel Better Errors
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/activemodel-better-errors.png)](http://badge.fury.io/rb/activemodel-better-errors)
|
4
|
+
[![Build Status](https://travis-ci.org/aq1018/activemodel-better-errors.png?branch=master)](https://travis-ci.org/aq1018/activemodel-better-errors)
|
5
|
+
[![Dependency Status](https://gemnasium.com/aq1018/activemodel-better-errors.png)](https://gemnasium.com/aq1018/activemodel-better-errors)
|
6
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/aq1018/activemodel-better-errors)
|
7
|
+
|
8
|
+
`activemodel-better-errors` is a `ActiveModel::Errors` compatible library to help you
|
9
|
+
customize the presentation of your error messages.
|
10
|
+
|
11
|
+
## Why Better Errors
|
12
|
+
|
13
|
+
In `ActiveModel::Errors`, when an error is added, it is pre translated into human readable string.
|
14
|
+
However, this becomes less ideal when output error messages in JSON or XML in your API.
|
15
|
+
Most of the times, we want error codes instead of human readable strings. This will allow
|
16
|
+
API consumers to translate them in their own application and provide more flexibility for your
|
17
|
+
API.
|
18
|
+
|
19
|
+
## How Better Errors Work
|
20
|
+
|
21
|
+
`activemodel-better-errors` works by sperating the concerns of error message storage and presentation.
|
22
|
+
`ActiveModel::Errors` really handles four tasks in a single class:
|
23
|
+
|
24
|
+
* error data storage
|
25
|
+
* presenting human readable errors using `#full_messages`
|
26
|
+
* presenting errors in Array / XML format with `#to_a` and `#to_xml`
|
27
|
+
* presenting errors in Hash / JSON format with `#to_hash` and `#as_json`
|
28
|
+
|
29
|
+
This gem seperates these concerns and allows users to plugin various reporters for different presentation needs.
|
30
|
+
|
31
|
+
## Setup
|
32
|
+
|
33
|
+
### With Bundler
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# in Gemfile
|
37
|
+
gem 'activemodel-better-errors', '>= 1.4.0'
|
38
|
+
```
|
39
|
+
|
40
|
+
```
|
41
|
+
# in console
|
42
|
+
bundle install
|
43
|
+
```
|
44
|
+
|
45
|
+
### With RubyGems
|
46
|
+
|
47
|
+
```
|
48
|
+
gem install activemodel-better-errors
|
49
|
+
```
|
50
|
+
|
51
|
+
## Configure
|
52
|
+
|
53
|
+
By default, `activemodel-better-errors` is a drop-in replacement for `ActiveModel::Errors`
|
54
|
+
and will mostly function without modifications. This is because the default reporters are set like the following:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
ActiveModel::ErrorCollecting.set_reporter :message, :human
|
58
|
+
ActiveModel::ErrorCollecting.set_reporter :array, :human
|
59
|
+
ActiveModel::ErrorCollecting.set_reporter :hash, :human
|
60
|
+
```
|
61
|
+
|
62
|
+
If you want to output API friendly JSON / XML by default, you can use the following config.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
ActiveModel::ErrorCollecting.set_reporter :message, :human
|
66
|
+
ActiveModel::ErrorCollecting.set_reporter :array, :machine
|
67
|
+
ActiveModel::ErrorCollecting.set_reporter :hash, :machine
|
68
|
+
```
|
69
|
+
|
70
|
+
Note: The configurations above determines *default* reporters to use, you can always switch to
|
71
|
+
any reporters you want during runtime by invoking `errors.set_reporter`
|
72
|
+
|
73
|
+
## Usage
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
user.errors # returns an instance of ActiveModel::ErrorCollecting::Errors
|
77
|
+
|
78
|
+
# Use MachineArrayReporter to output API friendly error messages
|
79
|
+
user.errors.set_reporter(:array, :machine)
|
80
|
+
user.errors.to_a # API Friendly
|
81
|
+
user.errors.to_xml # API Friendly
|
82
|
+
|
83
|
+
# Use HumanArrayReporter to output Human friendly error messages.
|
84
|
+
# This is ActiveModel::Errors behavior
|
85
|
+
user.errors.set_reporter(:array, :human)
|
86
|
+
user.errors.to_a # Human Friendly
|
87
|
+
user.errors.to_xml # Human Friendly
|
88
|
+
|
89
|
+
# Use MachineHashReporter to output API friendly error messages
|
90
|
+
user.errors.set_reporter(:hash, :machine)
|
91
|
+
user.errors.to_hash # API Friendly
|
92
|
+
user.errors.as_json # API Friendly
|
93
|
+
user.errors.to_json # API Friendly
|
94
|
+
|
95
|
+
|
96
|
+
# Use HumanHashReporter to output Human friendly error messages.
|
97
|
+
# This is ActiveModel::Errors behavior
|
98
|
+
user.errors.set_reporter(:hash, :human)
|
99
|
+
user.errors.to_hash # Human Friendly
|
100
|
+
user.errors.as_json # Human Friendly
|
101
|
+
user.errors.to_json # Human Friendly
|
102
|
+
|
103
|
+
# Use MyHashReporter to output Human friendly error messages.
|
104
|
+
# This is ActiveModel::Errors behavior
|
105
|
+
user.errors.set_reporter(:hash, MyHashReporter)
|
106
|
+
user.errors.to_hash # custom behavior
|
107
|
+
user.errors.as_json # custom behavior
|
108
|
+
user.errors.to_json # custom behavior
|
109
|
+
|
110
|
+
```
|
111
|
+
|
112
|
+
## In Depth
|
113
|
+
|
114
|
+
This library creates three types of reporters to take care of
|
115
|
+
some presentation aspects of `ActiveModel::Errors`, and they are:
|
116
|
+
|
117
|
+
**Message Reporters**
|
118
|
+
|
119
|
+
This is responsible for handling the following methods in `ActiveModel::Errors`
|
120
|
+
|
121
|
+
* `#full_messages`
|
122
|
+
* `#full_message`
|
123
|
+
* `#generate_message`
|
124
|
+
|
125
|
+
Due to the conventional use of these methods, they are mostly intended for human consumption.
|
126
|
+
|
127
|
+
This library implements the following reporters of this type:
|
128
|
+
|
129
|
+
* `HumanMessageReporter`
|
130
|
+
|
131
|
+
**Array Reporters**
|
132
|
+
|
133
|
+
This is responsible for handling the following methods in `ActiveModel::Errors`
|
134
|
+
|
135
|
+
* `#to_a`
|
136
|
+
|
137
|
+
This library implements the following reporters of this type:
|
138
|
+
|
139
|
+
* `HumanArrayReporter`
|
140
|
+
* `MachineArrayReporter`
|
141
|
+
|
142
|
+
**Hash Reporters**
|
143
|
+
|
144
|
+
This is responsible for handling the following methods in `ActiveModel::Errors`
|
145
|
+
|
146
|
+
* `#to_hash`
|
147
|
+
|
148
|
+
This library implements the following reporters of this type:
|
149
|
+
|
150
|
+
* `HumanHashReporter`
|
151
|
+
* `MachineHashReporter`
|
152
|
+
|
153
|
+
|
154
|
+
## Creating Custom Reporters
|
155
|
+
|
156
|
+
Creating a custom reporter is easy. Here is an example to create a hash reporter
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
class MyHashReporter < ActiveModel::ErrorCollecting::HashReporter
|
160
|
+
def to_hash
|
161
|
+
# you have access to #collection and #base
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# set it to use it.
|
166
|
+
ActiveModel::ErrorCollecting.set_reporter :hash, MyHashReporter
|
167
|
+
```
|
168
|
+
|
169
|
+
## Contributing to activemodel-better-errors
|
170
|
+
|
171
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
172
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
173
|
+
* Fork the project.
|
174
|
+
* Start a feature/bugfix branch.
|
175
|
+
* Commit and push until you are happy with your contribution.
|
176
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
177
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
178
|
+
|
179
|
+
## Copyright
|
180
|
+
|
181
|
+
Copyright (c) 2013 Aaron Qian. See LICENSE.txt for
|
182
|
+
further details.
|
183
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "active_model-better_errors"
|
18
|
+
gem.homepage = "http://github.com/aq1018/active_model-better_errors"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{API consumable error messages with ActiveModel::Errors drop-in compatibility.}
|
21
|
+
gem.description = %Q{ActiveModel::Errors class is not designed for API consumption. This gem allows for that while keeping compatibility with existing rails API.}
|
22
|
+
gem.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"]
|
23
|
+
gem.authors = ["Aaron Qian", "Byron Anderson"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
dir = File.dirname(__FILE__)
|
40
|
+
|
41
|
+
require 'rake/testtask'
|
42
|
+
|
43
|
+
test_files = []
|
44
|
+
test_files << "test/integration"
|
45
|
+
test_files += Dir.glob("#{dir}/vendor/rails/activemodel/test/cases/**/*_test.rb").sort
|
46
|
+
|
47
|
+
Rake::TestTask.new("test:integration") do |t|
|
48
|
+
t.libs << "vendor/rails/activemodel/test"
|
49
|
+
t.test_files = test_files
|
50
|
+
t.warning = true
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
task :default => [ :spec ]
|
55
|
+
|
56
|
+
require 'yard'
|
57
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.6.0
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "active_model-better_errors"
|
8
|
+
s.version = "1.6.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Aaron Qian", "Byron Anderson"]
|
12
|
+
s.date = "2013-01-22"
|
13
|
+
s.description = "ActiveModel::Errors class is not designed for API consumption. This gem allows for that while keeping compatibility with existing rails API."
|
14
|
+
s.email = ["aq1018@gmail.com", "byronanderson32@gmail.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitmodules",
|
22
|
+
".rspec",
|
23
|
+
".travis.yml",
|
24
|
+
"Gemfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"active_model-better_errors.gemspec",
|
30
|
+
"lib/active_model/better_errors.rb",
|
31
|
+
"lib/active_model/error_collecting.rb",
|
32
|
+
"lib/active_model/error_collecting/array_reporter.rb",
|
33
|
+
"lib/active_model/error_collecting/core_ext.rb",
|
34
|
+
"lib/active_model/error_collecting/emulation.rb",
|
35
|
+
"lib/active_model/error_collecting/error_collection.rb",
|
36
|
+
"lib/active_model/error_collecting/error_message.rb",
|
37
|
+
"lib/active_model/error_collecting/error_message_set.rb",
|
38
|
+
"lib/active_model/error_collecting/errors.rb",
|
39
|
+
"lib/active_model/error_collecting/hash_reporter.rb",
|
40
|
+
"lib/active_model/error_collecting/human_array_reporter.rb",
|
41
|
+
"lib/active_model/error_collecting/human_hash_reporter.rb",
|
42
|
+
"lib/active_model/error_collecting/human_message_formatter.rb",
|
43
|
+
"lib/active_model/error_collecting/human_message_reporter.rb",
|
44
|
+
"lib/active_model/error_collecting/machine_array_reporter.rb",
|
45
|
+
"lib/active_model/error_collecting/machine_hash_reporter.rb",
|
46
|
+
"lib/active_model/error_collecting/message_reporter.rb",
|
47
|
+
"lib/active_model/error_collecting/reporter.rb",
|
48
|
+
"spec/lib/active_model/better_errors_spec.rb",
|
49
|
+
"spec/lib/active_model/error_collecting/emulation_spec.rb",
|
50
|
+
"spec/lib/active_model/error_collecting/error_collection_spec.rb",
|
51
|
+
"spec/lib/active_model/error_collecting/error_message_set_spec.rb",
|
52
|
+
"spec/lib/active_model/error_collecting/error_message_spec.rb",
|
53
|
+
"spec/lib/active_model/error_collecting/errors_spec.rb",
|
54
|
+
"spec/lib/active_model/error_collecting/human_array_reporter_spec.rb",
|
55
|
+
"spec/lib/active_model/error_collecting/human_hash_reporter_spec.rb",
|
56
|
+
"spec/lib/active_model/error_collecting/human_message_formatter_spec.rb",
|
57
|
+
"spec/lib/active_model/error_collecting/human_message_reporter_spec.rb",
|
58
|
+
"spec/lib/active_model/error_collecting/machine_array_reporter_spec.rb",
|
59
|
+
"spec/lib/active_model/error_collecting/machine_hash_reporter_spec.rb",
|
60
|
+
"spec/lib/active_model/error_collecting_spec.rb",
|
61
|
+
"spec/spec_helper.rb",
|
62
|
+
"spec/support/models.rb",
|
63
|
+
"test/integration.rb"
|
64
|
+
]
|
65
|
+
s.homepage = "http://github.com/aq1018/active_model-better_errors"
|
66
|
+
s.licenses = ["MIT"]
|
67
|
+
s.require_paths = ["lib"]
|
68
|
+
s.rubygems_version = "1.8.24"
|
69
|
+
s.summary = "API consumable error messages with ActiveModel::Errors drop-in compatibility."
|
70
|
+
|
71
|
+
if s.respond_to? :specification_version then
|
72
|
+
s.specification_version = 3
|
73
|
+
|
74
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
75
|
+
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0"])
|
76
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.12.0"])
|
78
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
80
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
81
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
82
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
83
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
84
|
+
s.add_development_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
85
|
+
s.add_development_dependency(%q<mocha>, [">= 0.12.1"])
|
86
|
+
else
|
87
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
88
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
89
|
+
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
90
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
91
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
92
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
93
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
94
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
95
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
96
|
+
s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
97
|
+
s.add_dependency(%q<mocha>, [">= 0.12.1"])
|
98
|
+
end
|
99
|
+
else
|
100
|
+
s.add_dependency(%q<activemodel>, ["~> 3.0"])
|
101
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
102
|
+
s.add_dependency(%q<rspec>, ["~> 2.12.0"])
|
103
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
104
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
105
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
106
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
107
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
108
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
109
|
+
s.add_dependency(%q<bcrypt-ruby>, ["~> 3.0.0"])
|
110
|
+
s.add_dependency(%q<mocha>, [">= 0.12.1"])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
|
5
|
+
require 'active_model/error_collecting'
|
6
|
+
|
7
|
+
require 'active_model/validations'
|
8
|
+
|
9
|
+
module ActiveModel
|
10
|
+
module Validations
|
11
|
+
def errors
|
12
|
+
@errors ||= ErrorCollecting::Errors.new(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'active_model/error_collecting/error_message'
|
2
|
+
require 'active_model/error_collecting/error_message_set'
|
3
|
+
require 'active_model/error_collecting/error_collection'
|
4
|
+
|
5
|
+
require 'active_model/error_collecting/reporter'
|
6
|
+
require 'active_model/error_collecting/message_reporter'
|
7
|
+
require 'active_model/error_collecting/hash_reporter'
|
8
|
+
require 'active_model/error_collecting/array_reporter'
|
9
|
+
|
10
|
+
require 'active_model/error_collecting/human_message_formatter'
|
11
|
+
require 'active_model/error_collecting/human_message_reporter'
|
12
|
+
require 'active_model/error_collecting/human_hash_reporter'
|
13
|
+
require 'active_model/error_collecting/human_array_reporter'
|
14
|
+
|
15
|
+
require 'active_model/error_collecting/machine_hash_reporter'
|
16
|
+
require 'active_model/error_collecting/machine_array_reporter'
|
17
|
+
|
18
|
+
require 'active_model/error_collecting/emulation'
|
19
|
+
require 'active_model/error_collecting/errors'
|
20
|
+
|
21
|
+
require 'active_model/error_collecting/core_ext'
|
22
|
+
|
23
|
+
module ActiveModel
|
24
|
+
module ErrorCollecting
|
25
|
+
class << self
|
26
|
+
def set_reporter(name, reporter)
|
27
|
+
name = name.to_s
|
28
|
+
@reporter_maps ||= {}
|
29
|
+
return @reporter_maps.delete(name) unless reporter
|
30
|
+
@reporter_maps[name] = get_reporter_class(name, reporter)
|
31
|
+
end
|
32
|
+
|
33
|
+
def reporters
|
34
|
+
@reporter_maps ||= {}
|
35
|
+
@reporter_maps.clone
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_reporter_class(name, reporter)
|
39
|
+
return reporter if reporter.is_a? Class
|
40
|
+
class_name = "active_model/error_collecting/#{reporter}_#{name}_reporter"
|
41
|
+
class_name.classify.constantize
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
set_reporter :message, :human
|
46
|
+
set_reporter :array, :human
|
47
|
+
set_reporter :hash, :human
|
48
|
+
end
|
49
|
+
end
|