validator_attachment 0.3.0

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/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ v0.3.0 now should be ok
2
+ v0.2.0 stupid error removed
3
+ v0.1.1 removed iml file
4
+ v0.1.0 initial version
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+ README.rdoc
3
+ Rakefile
4
+ lib/validator_attachment.rb
5
+ validator_attachment.gemspec
6
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == Validator Attachment
2
+
3
+ (documentation will soon be provided)
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('validator_attachment', '0.3.0') do |p|
6
+ p.summary = "Is this ActiveModel Validator Used?"
7
+ p.description = "Checks whether an ActiveModel Validator is attached to an attribute of a Model and with which options"
8
+ p.url = "http://github.com/pmatsinopoulos/validator_attachment"
9
+ p.author = "Panayotis Matsinopoulos"
10
+ p.email = "panayotis@matsinopoulos.gr"
11
+ p.ignore_pattern = ["tmp/*", "script/*"]
12
+ p.development_dependencies = []
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{ |ext| load ext }
16
+
17
+
@@ -0,0 +1,33 @@
1
+ module ValidatorAttachment
2
+ def is_attached?(klass, attribute, options=nil, exact_match=false)
3
+ validators = klass._validate_callbacks.map{|vc| vc.raw_filter}
4
+ validators = validators.find_all{ |val| val.is_a?(self) }
5
+ return false unless validators.present?
6
+
7
+ # for those validators I am interested in those that they have attributes that include the attribute
8
+ validators = validators.find_all{ |val| val.attributes.present? && val.attributes.include?(attribute)}
9
+ return false unless validators.present?
10
+
11
+ # if options given, then validator needs to have these options too
12
+ if options.present?
13
+ if exact_match
14
+ validators = validators.find_all{|val| val.options.present? && val.options == options}
15
+ else
16
+ # In this case, I want to find all the 'options' inside the options of the validator.
17
+ # Even if validator has more options this is acceptable
18
+ # The logic of comparison:
19
+ # I find the difference of +val.options+ to +options+ and then I remove from +val.options+ this difference.
20
+ # The remaining keys of +val.options+ should be hash equal to +options+
21
+ validators = validators.find_all{|val| val.options.present? && val.options.reject{|k,v| val.options.diff(options).keys.include?(k)} == options}
22
+ end
23
+ end
24
+
25
+ validators.present?
26
+ end
27
+ end
28
+
29
+ module ActiveModel
30
+ class EachValidator
31
+ extend ValidatorAttachment
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{validator_attachment}
5
+ s.version = "0.3.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Panayotis Matsinopoulos}]
9
+ s.date = %q{2011-10-14}
10
+ s.description = %q{Checks whether an ActiveModel Validator is attached to an attribute of a Model and with which options}
11
+ s.email = %q{panayotis@matsinopoulos.gr}
12
+ s.extra_rdoc_files = [%q{CHANGELOG}, %q{README.rdoc}, %q{lib/validator_attachment.rb}]
13
+ s.files = [%q{CHANGELOG}, %q{README.rdoc}, %q{Rakefile}, %q{lib/validator_attachment.rb}, %q{validator_attachment.gemspec}, %q{Manifest}]
14
+ s.homepage = %q{http://github.com/pmatsinopoulos/validator_attachment}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Validator_attachment}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{validator_attachment}
18
+ s.rubygems_version = %q{1.8.8}
19
+ s.summary = %q{Is this ActiveModel Validator Used?}
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
+ else
26
+ end
27
+ else
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validator_attachment
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
+ platform: ruby
12
+ authors:
13
+ - Panayotis Matsinopoulos
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-14 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Checks whether an ActiveModel Validator is attached to an attribute of a Model and with which options
22
+ email: panayotis@matsinopoulos.gr
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - CHANGELOG
29
+ - README.rdoc
30
+ - lib/validator_attachment.rb
31
+ files:
32
+ - CHANGELOG
33
+ - README.rdoc
34
+ - Rakefile
35
+ - lib/validator_attachment.rb
36
+ - validator_attachment.gemspec
37
+ - Manifest
38
+ homepage: http://github.com/pmatsinopoulos/validator_attachment
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --line-numbers
44
+ - --inline-source
45
+ - --title
46
+ - Validator_attachment
47
+ - --main
48
+ - README.rdoc
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 11
66
+ segments:
67
+ - 1
68
+ - 2
69
+ version: "1.2"
70
+ requirements: []
71
+
72
+ rubyforge_project: validator_attachment
73
+ rubygems_version: 1.8.8
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Is this ActiveModel Validator Used?
77
+ test_files: []
78
+