ames_by_type 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +61 -0
- data/README.rdoc +30 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/ames_by_type.rb +36 -0
- data/spec/ames_by_type_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa5b9b0c015e27d8c02d60a6b74514cc211fc705
|
4
|
+
data.tar.gz: 6f5c387a1abb4430fbccd338724ac4dfc7d0cbfb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f75bf304122650c27e928a0a16ecfec07d004306c03d01a1b7404f06ae8564146b7800bdebec2fe42c311e039e3308f26f632f1c26c468c99e1f3c5c96193e1
|
7
|
+
data.tar.gz: 01b1e811be5e4a25930978138bd3378bb0d9d03f142a5936664c3cfd3a618e4b20b4d81c39c34d351efa849be1dde90d08bdb0306c9d35b697da8d199c762665
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 1.8.7"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
faraday (0.8.9)
|
8
|
+
multipart-post (~> 1.2.0)
|
9
|
+
git (1.2.6)
|
10
|
+
github_api (0.10.1)
|
11
|
+
addressable
|
12
|
+
faraday (~> 0.8.1)
|
13
|
+
hashie (>= 1.2)
|
14
|
+
multi_json (~> 1.4)
|
15
|
+
nokogiri (~> 1.5.2)
|
16
|
+
oauth2
|
17
|
+
hashie (2.0.5)
|
18
|
+
highline (1.6.20)
|
19
|
+
jeweler (1.8.8)
|
20
|
+
builder
|
21
|
+
bundler (~> 1.0)
|
22
|
+
git (>= 1.2.5)
|
23
|
+
github_api (= 0.10.1)
|
24
|
+
highline (>= 1.6.15)
|
25
|
+
nokogiri (= 1.5.10)
|
26
|
+
rake
|
27
|
+
rdoc
|
28
|
+
json (1.8.1)
|
29
|
+
jwt (0.1.11)
|
30
|
+
multi_json (>= 1.5)
|
31
|
+
multi_json (1.8.4)
|
32
|
+
multi_xml (0.5.5)
|
33
|
+
multipart-post (1.2.0)
|
34
|
+
nokogiri (1.5.10)
|
35
|
+
oauth2 (0.9.3)
|
36
|
+
faraday (>= 0.8, < 0.10)
|
37
|
+
jwt (~> 0.1.8)
|
38
|
+
multi_json (~> 1.3)
|
39
|
+
multi_xml (~> 0.5)
|
40
|
+
rack (~> 1.2)
|
41
|
+
rack (1.5.2)
|
42
|
+
rake (10.1.1)
|
43
|
+
rdoc (3.12.2)
|
44
|
+
json (~> 1.4)
|
45
|
+
rspec (2.8.0)
|
46
|
+
rspec-core (~> 2.8.0)
|
47
|
+
rspec-expectations (~> 2.8.0)
|
48
|
+
rspec-mocks (~> 2.8.0)
|
49
|
+
rspec-core (2.8.0)
|
50
|
+
rspec-expectations (2.8.0)
|
51
|
+
diff-lcs (~> 1.1.2)
|
52
|
+
rspec-mocks (2.8.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 1.0)
|
59
|
+
jeweler (~> 1.8.7)
|
60
|
+
rdoc (~> 3.12)
|
61
|
+
rspec (~> 2.8.0)
|
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
== ActiveModel::Errors #by_type
|
2
|
+
|
3
|
+
Use +#by_type+ on an instance of <tt>ActiveModel::Errors</tt> (presumably in Rails) to
|
4
|
+
retrieve a hash of error messages scoped by attribute and type. Empower your
|
5
|
+
server-sent, serialized form/record validation messages to play nicely with data-binding JS
|
6
|
+
frameworks. Get more granular with your validation UIs.
|
7
|
+
|
8
|
+
==== Copyright
|
9
|
+
|
10
|
+
Copyright (c) 2014 Travis Loncar.
|
11
|
+
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
a copy of this software and associated documentation files (the
|
14
|
+
"Software"), to deal in the Software without restriction, including
|
15
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be
|
21
|
+
included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
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 = "ames_by_type"
|
18
|
+
gem.homepage = "http://github.com/tbloncar/ames_by_type"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "Extends ActiveModel::Errors with errors by type."
|
21
|
+
gem.description = "This gem extends the functionality of Rails' ActiveModel::Errors
|
22
|
+
with a #by_type method that returns a hash of error messages
|
23
|
+
scoped by attribute and type."
|
24
|
+
gem.email = "loncar.travis@gmail.com"
|
25
|
+
gem.authors = ["Travis Loncar"]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "ames_by_type #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/ames_by_type.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
class Errors
|
3
|
+
attr_reader :messages_by_type
|
4
|
+
|
5
|
+
def initialize(base)
|
6
|
+
@base = base
|
7
|
+
@messages = {}
|
8
|
+
@messages_by_type = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(attribute, message = :invalid, options = {})
|
12
|
+
normalized_message = normalize_message(attribute, message, options)
|
13
|
+
if exception = options[:strict]
|
14
|
+
exception = ActiveModel::StrictValidationFailed if exception == true
|
15
|
+
raise exception, full_message(attribute, message)
|
16
|
+
end
|
17
|
+
|
18
|
+
if message.is_a?(Symbol)
|
19
|
+
message_by_type = {}
|
20
|
+
message_by_type[message] = normalized_message
|
21
|
+
self.messages_by_type[attribute] = (self.messages_by_type[attribute] || {}).merge(message_by_type)
|
22
|
+
end
|
23
|
+
|
24
|
+
self[attribute] = normalized_message
|
25
|
+
end
|
26
|
+
|
27
|
+
def by_type(full_messages: false)
|
28
|
+
return messages_by_type.dup unless full_messages
|
29
|
+
messages_by_type.each do |attribute, messages|
|
30
|
+
messages.each do |type, message|
|
31
|
+
messages_by_type[attribute][type] = full_message(attribute, message)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ames_by_type'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ames_by_type
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Loncar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.8.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.8.7
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.7
|
69
|
+
description: |-
|
70
|
+
This gem extends the functionality of Rails' ActiveModel::Errors
|
71
|
+
with a #by_type method that returns a hash of error messages
|
72
|
+
scoped by attribute and type.
|
73
|
+
email: loncar.travis@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files:
|
77
|
+
- README.rdoc
|
78
|
+
files:
|
79
|
+
- ".document"
|
80
|
+
- ".rspec"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- README.rdoc
|
84
|
+
- Rakefile
|
85
|
+
- VERSION
|
86
|
+
- lib/ames_by_type.rb
|
87
|
+
- spec/ames_by_type_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: http://github.com/tbloncar/ames_by_type
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Extends ActiveModel::Errors with errors by type.
|
113
|
+
test_files: []
|