association_validator 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +4 -0
- data/Rakefile +12 -0
- data/association_validator.gemspec +32 -0
- data/lib/association_validator.rb +19 -0
- metadata +66 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('association_validator', '0.5.0') do |p|
|
6
|
+
p.description = "Rails 3 assocation validation for id fields"
|
7
|
+
p.url = "http://github.com/TheEmpty"
|
8
|
+
p.author = "Mohammad El-Abid"
|
9
|
+
p.email = "mohammad {dot} elabid {at} gmail"
|
10
|
+
p.ignore_pattern = []
|
11
|
+
p.development_dependencies = [["activemodel", ">= 3.0.0"]]
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{association_validator}
|
5
|
+
s.version = "0.5.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Mohammad El-Abid"]
|
9
|
+
s.date = %q{2011-03-23}
|
10
|
+
s.description = %q{Rails 3 assocation validation for id fields}
|
11
|
+
s.email = %q{mohammad {dot} elabid {at} gmail}
|
12
|
+
s.extra_rdoc_files = ["lib/association_validator.rb"]
|
13
|
+
s.files = ["Manifest", "Rakefile", "association_validator.gemspec", "lib/association_validator.rb"]
|
14
|
+
s.homepage = %q{http://github.com/TheEmpty}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Association_validator"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{association_validator}
|
18
|
+
s.rubygems_version = %q{1.6.2}
|
19
|
+
s.summary = %q{Rails 3 assocation validation for id fields}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_development_dependency(%q<activemodel>, [">= 3.0.0"])
|
26
|
+
else
|
27
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
28
|
+
end
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0"])
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class AssociationValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
return if record.send(attribute).blank? # return if value.blank? # use :presence => true if you want to confirm that something is there
|
4
|
+
|
5
|
+
if options[:class_name].blank?
|
6
|
+
attribute_string = attribute.to_s
|
7
|
+
attribute_string[-3,3] = ''
|
8
|
+
else
|
9
|
+
attribute_string = options[:class_name]
|
10
|
+
end
|
11
|
+
|
12
|
+
c = attribute_string.camelize.constantize # create a refrence to the class
|
13
|
+
begin
|
14
|
+
valid = c.find(value, :select => 'id') # activerecord will raise an exception if it's not found, so we're going to catch it
|
15
|
+
rescue
|
16
|
+
record.errors[attribute] = "is a non existent record" # and report that it doesn't exist
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: association_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mohammad El-Abid
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-03-23 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activemodel
|
17
|
+
requirement: &27622104 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *27622104
|
26
|
+
description: Rails 3 assocation validation for id fields
|
27
|
+
email: mohammad {dot} elabid {at} gmail
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files:
|
31
|
+
- lib/association_validator.rb
|
32
|
+
files:
|
33
|
+
- Manifest
|
34
|
+
- Rakefile
|
35
|
+
- association_validator.gemspec
|
36
|
+
- lib/association_validator.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/TheEmpty
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --line-numbers
|
43
|
+
- --inline-source
|
44
|
+
- --title
|
45
|
+
- Association_validator
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.2'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project: association_validator
|
62
|
+
rubygems_version: 1.6.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Rails 3 assocation validation for id fields
|
66
|
+
test_files: []
|