association_validator 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -7,6 +7,14 @@ validates :user_id, :presence => true, :association => true</code></pre>
7
7
  You can also set the message using the :message option:
8
8
  <pre><code>validates :user_id, :association => {:message => 'was unretrievable'}</code></pre>
9
9
 
10
+ For polymorphic classes, pass your class_name option as a proc:
11
+ <pre><code>class Item < ActiveRecord::Base
12
+ validates :owner_id, :presence => true, :association => {:class_name => Proc.new {|r| r.owner_type}}
13
+ end
14
+ # == Schema Information
15
+ # Table name: items
16
+ # owner_id :integer
17
+ # owner_type :string</code></pre>
10
18
 
11
19
  h1. How to install
12
20
 
data/README.txt CHANGED
@@ -5,6 +5,15 @@ Validate that the id field is a saved record. It will ignore blank fields, so us
5
5
 
6
6
  You can also set the message using the :message option:
7
7
  validates :user_id, :association => {:message => 'was unretrievable'}
8
+
9
+ For polymorphic classes, pass your class_name option as a proc:
10
+ class Item < ActiveRecord::Base
11
+ validates :owner_id, :presence => true, :association => {:class_name => Proc.new {|r| r.owner_type}}
12
+ end
13
+ # == Schema Information
14
+ # Table name: items
15
+ # owner_id :integer
16
+ # owner_type :string
8
17
 
9
18
  === How to install
10
19
  Add the following line to your Gemfile and install.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('association_validator', '0.5.4') do |p|
5
+ Echoe.new('association_validator', '0.6.0') do |p|
6
6
  p.description = "Rails 3 assocation validation for id fields"
7
7
  p.url = "http://github.com/TheEmpty"
8
8
  p.author = "Mohammad El-Abid"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{association_validator}
5
- s.version = "0.5.4"
5
+ s.version = "0.6.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mohammad El-Abid"]
@@ -5,8 +5,12 @@ class AssociationValidator < ActiveModel::EachValidator
5
5
  if options[:class_name].blank?
6
6
  attribute_string = attribute.to_s
7
7
  attribute_string[-3,3] = ''
8
- else
8
+ elsif options[:class_name].is_a?(String)
9
9
  attribute_string = options[:class_name]
10
+ elsif options[:class_name].is_a?(Proc)
11
+ attribute_string = options[:class_name].yield(record)
12
+ else
13
+ raise "Association Validator does not support a(n) #{options[:class_name].class.to_s.humanize} as a class_name option"
10
14
  end
11
15
 
12
16
  c = attribute_string.camelize.constantize # create a refrence to the class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &27813468 !ruby/object:Gem::Requirement
17
+ requirement: &30028020 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *27813468
25
+ version_requirements: *30028020
26
26
  description: Rails 3 assocation validation for id fields
27
27
  email: mohammad {dot} elabid {at} gmail
28
28
  executables: []