simple_activemodel_validators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92223014f68fe4536c457afa5bbcfd19eff6da55
4
+ data.tar.gz: 05e2f6999b819b63904f0f0cf67e2a086ceb7586
5
+ SHA512:
6
+ metadata.gz: 6376c962c3b870a2c6b333230bda4b219819811a29cb56463bb6608c7e609f48e578b2bf130746d987dd1f10525bbd2ad90e8d5d0ce0eec76c511dd2f248156e
7
+ data.tar.gz: 69f00ff48c48ef06855f6686a11ac0c4c50834afa4ab991cb110243dfd45c328de67bc274ed4f9c6a857e9ea822a7a085e706f3bbb4cda440653a62777dcdf48
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --no-private
2
+ --hide-void-return
3
+ --markup-provider=redcarpet
4
+ --markup=markdown
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Decomplect Software LLP
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ [![Build Status](https://travis-ci.org/decomplect-io/simple_activemodel_validators.svg)](https://travis-ci.org/decomplect-io/simple_activemodel_validators)
2
+ # Simple ActiveModel Validators
3
+
4
+ A collection of ActiveModel validators that don't pollute the global namespace.
5
+
6
+ List of available validators:
7
+
8
+ - `SimpleActiveModelValidators::AssociatedBubblingValidator`
9
+
10
+ Bubbles up associated validation errors on to the main model.
11
+ For example
12
+ ```ruby
13
+ class User < ActiveRecord::Base
14
+ validates :name, presence: true
15
+ has_many :comments
16
+ validates_with SimpleActiveModelValidators::AssociatedBubblingValidator, attributes: [:comments]
17
+ end
18
+
19
+ class Comment < ActiveRecord::Base
20
+ belongs_to :user
21
+ validates :body, presence: true
22
+ end
23
+
24
+ user = User.new(name: 'Joe', comments: [Comment.new(body: '')])
25
+ user.valid?
26
+ user.errors.messages == { comments: ["is invalid", { body: ["can't be blank"] }] }
27
+ ```
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'simple_activemodel_validators'
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/decomplect-io/simple_activemodel_validators.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_activemodel_validators"
5
+ require "irb"
6
+ require 'irb/completion'
7
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path vendor/bundle -j4
data/bin/yard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yard')
data/bin/yardoc ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yardoc' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yardoc')
data/bin/yri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'yri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('yard', 'yri')
@@ -0,0 +1,33 @@
1
+ module SimpleActiveModelValidators
2
+ # Bubbles up associated validation errors on to the main model.
3
+ # For example
4
+ # ```ruby
5
+ # class User < ActiveRecord::Base
6
+ # validates :name, presence: true
7
+ # has_many :comments
8
+ # validates_with SimpleActiveModelValidators::AssociatedBubblingValidator, attributes: [:comments]
9
+ # end
10
+ #
11
+ # class Comment < ActiveRecord::Base
12
+ # belongs_to :user
13
+ # validates :body, presence: true
14
+ # end
15
+ #
16
+ # user = User.new(name: 'Joe', comments: [Comment.new(body: '')])
17
+ # user.valid?
18
+ # user.errors.messages == { comments: ["is invalid", { body: ["can't be blank"] }] }
19
+ # ```
20
+ #
21
+ # Similar to [validates_associated](1) with the extra error bubbling feature.
22
+ # [1]: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_associated
23
+ class AssociatedBubblingValidator < ActiveModel::EachValidator
24
+ # Implements the contract of `ActiveModel::EachValidator`
25
+ # @return nil
26
+ def validate_each(record, attribute, values)
27
+ # values can be an array or a scalar
28
+ [values].flatten.reject(&:valid?).each do |value|
29
+ record.errors.add(attribute, value.errors.messages)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleActiveModelValidators
2
+ # Gem version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,7 @@
1
+ require "simple_activemodel_validators/version"
2
+ require 'active_model'
3
+
4
+ # A collection of ActiveModel validators that don't pollute the global namespace.
5
+ module SimpleActiveModelValidators
6
+ require 'simple_activemodel_validators/associated_bubbling_validator'
7
+ end
@@ -0,0 +1,40 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'simple_activemodel_validators/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simple_activemodel_validators"
7
+ spec.version = SimpleActiveModelValidators::VERSION
8
+ spec.authors = ["Decomplect Software LLP"]
9
+ spec.email = ["hello@decomplect.io"]
10
+
11
+ spec.summary = %(A collection of ActiveModel validators that don't pollute the global namespace.)
12
+ spec.homepage = "https://github.com/decomplect-io/simple_activemodel_validators"
13
+ spec.license = "MIT"
14
+ spec.files = `git ls-files`.split($RS).reject do |file|
15
+ file =~ %r{^(?:
16
+ spec/.*
17
+ |Gemfile
18
+ |Rakefile
19
+ |\.rspec
20
+ |\.gitignore
21
+ |\.rubocop.yml
22
+ |\.travis.yml
23
+ )$}x
24
+ end
25
+ spec.require_paths = ["lib"]
26
+ spec.test_files = []
27
+ spec.executables = []
28
+ spec.extra_rdoc_files = ['LICENSE.txt', 'README.md']
29
+
30
+ spec.add_dependency "activemodel", "~> 4.2"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rubocop", "~> 0.3"
35
+ spec.add_development_dependency "rspec", "~> 3.3"
36
+ spec.add_development_dependency "activerecord", "~> 4.2"
37
+ spec.add_development_dependency "sqlite3", "~> 1.3"
38
+ spec.add_development_dependency "yard", "~> 0.8"
39
+ spec.add_development_dependency "redcarpet", "~> 3.3"
40
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_activemodel_validators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Decomplect Software LLP
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-23 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: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: redcarpet
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.3'
139
+ description:
140
+ email:
141
+ - hello@decomplect.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - LICENSE.txt
146
+ - README.md
147
+ files:
148
+ - ".yardopts"
149
+ - LICENSE.txt
150
+ - README.md
151
+ - bin/console
152
+ - bin/rake
153
+ - bin/rspec
154
+ - bin/rubocop
155
+ - bin/setup
156
+ - bin/yard
157
+ - bin/yardoc
158
+ - bin/yri
159
+ - lib/simple_activemodel_validators.rb
160
+ - lib/simple_activemodel_validators/associated_bubbling_validator.rb
161
+ - lib/simple_activemodel_validators/version.rb
162
+ - simple_activemodel_validators.gemspec
163
+ homepage: https://github.com/decomplect-io/simple_activemodel_validators
164
+ licenses:
165
+ - MIT
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.4.8
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: A collection of ActiveModel validators that don't pollute the global namespace.
187
+ test_files: []
188
+ has_rdoc: