subset_validator 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -1,6 +1,34 @@
1
1
  class SubsetValidator < ActiveModel::EachValidator
2
2
  @@error_message = 'contains an invalid value'
3
3
 
4
+ # Validate that the specified attribute's value is a subset of another set.
5
+ #
6
+ # Note that this works on more than just arrays, too. It'll work on anything, provided that:
7
+ # * the attribute's value can be anything that responds to <i>#each</i> ;
8
+ # * the set of valid values can be anything that responds to <i>#include?</i> .
9
+ #
10
+ # @example
11
+ # class User
12
+ # include ActiveModel::Validations
13
+ #
14
+ # attr_accessor :roles
15
+ #
16
+ # @@valid_roles = %w(admin manager developer)
17
+ #
18
+ # validates :roles, :subset => {:in => @@valid_roles}
19
+ # end
20
+ #
21
+ # u = User.new
22
+ # u.roles = %w(admin something_else)
23
+ #
24
+ # u.valid?
25
+ # => false
26
+ # u.errors
27
+ # => {:roles=>["contains an invalid value"]}
28
+ #
29
+ # u.roles = %w(admin)
30
+ # u.valid?
31
+ # => true
4
32
  def validate_each(record, attribute, value)
5
33
  unless options[:in].respond_to? :include?
6
34
  raise ArgumentError, 'An object with the method include? must be supplied as the :in option of the configuration hash'
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{subset_validator}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nick Hoffman"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nick Hoffman
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- hash: -197131887
116
+ hash: 479483101
117
117
  segments:
118
118
  - 0
119
119
  version: "0"