activemodel_errors_type 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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/activemodel_errors_type.gemspec +26 -0
- data/lib/activemodel_errors_type/errors_type.rb +30 -0
- data/lib/activemodel_errors_type/version.rb +3 -0
- data/lib/activemodel_errors_type.rb +6 -0
- data/spec/activemodel_errors_type_spec.rb +49 -0
- data/spec/spec_helper.rb +17 -0
- metadata +132 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adrien Siami
|
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,29 @@
|
|
1
|
+
# ActivemodelErrorsType
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'activemodel_errors_type'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install activemodel_errors_type
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activemodel_errors_type/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activemodel_errors_type"
|
8
|
+
spec.version = ActivemodelErrorsType::VERSION
|
9
|
+
spec.authors = ["Adrien Siami"]
|
10
|
+
spec.email = ["adrien@siami.fr"]
|
11
|
+
spec.description = "Allows to get errors type from an activemodel class, as a symbol, prior to the translation "
|
12
|
+
spec.summary = "Allows to get errors type from an activemodel class, as a symbol, prior to the translation "
|
13
|
+
spec.homepage = "https://github.com/Intrepidd/activemodel_errors_type"
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", '~> 2.13.0'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'activemodel', '>= 3.0', '< 5.0'
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveModelErrorsType
|
2
|
+
module ErrorsType
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.alias_method_chain :initialize, :errors
|
6
|
+
base.alias_method_chain :generate_message, :errors
|
7
|
+
base.alias_method_chain :clear, :errors
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize_with_errors(base)
|
11
|
+
@errors_type = {}
|
12
|
+
initialize_without_errors(base)
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_message_with_errors(attribute, type = :invalid, options = {})
|
16
|
+
@errors_type[attribute.to_sym] = type
|
17
|
+
generate_message_without_errors(attribute, type, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_with_errors
|
21
|
+
@errors_type.clear
|
22
|
+
clear_without_errors
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_types
|
26
|
+
@errors_type
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_model'
|
3
|
+
require 'activemodel_errors_type'
|
4
|
+
|
5
|
+
describe ActiveModel::Errors do
|
6
|
+
|
7
|
+
class DummyClass
|
8
|
+
include ActiveModel::Validations
|
9
|
+
include ActiveModel::Conversion
|
10
|
+
extend ActiveModel::Naming
|
11
|
+
|
12
|
+
attr_accessor :foo, :bar, :baz
|
13
|
+
|
14
|
+
validates :foo, :presence => true
|
15
|
+
validates :bar, :inclusion => { :in => 0..99 }
|
16
|
+
validates :baz, :numericality => true
|
17
|
+
|
18
|
+
def initialize(attributes = {})
|
19
|
+
attributes.each do |name, value|
|
20
|
+
send("#{name}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def persisted?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
@d = DummyClass.new
|
31
|
+
@d.valid?
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return correct error types' do
|
35
|
+
@d.valid?.should == false
|
36
|
+
types = @d.errors.with_types
|
37
|
+
types.should be_a(Hash)
|
38
|
+
types[:foo].should == :blank
|
39
|
+
types[:bar].should == :inclusion
|
40
|
+
types[:baz].should == :not_a_number
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should clear the errors when fixed' do
|
44
|
+
@d.foo = 'foo'
|
45
|
+
@d.valid?.should == false
|
46
|
+
@d.errors.with_types[:foo].should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activemodel_errors_type
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrien Siami
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
none: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.13.0
|
53
|
+
none: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 2.13.0
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activemodel
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- - <
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '5.0'
|
72
|
+
none: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.0'
|
78
|
+
- - <
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '5.0'
|
81
|
+
none: false
|
82
|
+
prerelease: false
|
83
|
+
type: :runtime
|
84
|
+
description: ! 'Allows to get errors type from an activemodel class, as a symbol,
|
85
|
+
prior to the translation '
|
86
|
+
email:
|
87
|
+
- adrien@siami.fr
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- activemodel_errors_type.gemspec
|
99
|
+
- lib/activemodel_errors_type.rb
|
100
|
+
- lib/activemodel_errors_type/errors_type.rb
|
101
|
+
- lib/activemodel_errors_type/version.rb
|
102
|
+
- spec/activemodel_errors_type_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/Intrepidd/activemodel_errors_type
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
none: false
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
none: false
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.25
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Allows to get errors type from an activemodel class, as a symbol, prior to
|
129
|
+
the translation
|
130
|
+
test_files:
|
131
|
+
- spec/activemodel_errors_type_spec.rb
|
132
|
+
- spec/spec_helper.rb
|