validatable-active_model 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +8 -0
- data/lib/validatable/active_model.rb +78 -0
- metadata +146 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Brian Cardarella
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'validatable'
|
2
|
+
|
3
|
+
module Validatable
|
4
|
+
module ActiveModelInterface
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def _validators
|
8
|
+
self.class._validators
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def _validators
|
14
|
+
validation_hash = Hash.new { |h, k| h[k] = [] }
|
15
|
+
|
16
|
+
validations.each do |validation|
|
17
|
+
validation_hash[validation.attribute.to_sym] << validation
|
18
|
+
end
|
19
|
+
|
20
|
+
validation_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def validators
|
24
|
+
_validators.values.flatten.uniq
|
25
|
+
end
|
26
|
+
|
27
|
+
def validators_on(attribute)
|
28
|
+
_validators[attribute.to_sym]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module ValidationBase
|
33
|
+
def kind
|
34
|
+
self.macro.to_s.match(/^[a-z]+_([a-z]+)/)[1].to_sym
|
35
|
+
end
|
36
|
+
|
37
|
+
def kind=(kind)
|
38
|
+
if kind.to_s == "associated"
|
39
|
+
self.instance_variable_set('@macro', "validates_associated".to_sym)
|
40
|
+
else
|
41
|
+
self.instance_variable_set('@macro', "validates_#{kind}_of".to_sym)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def macro
|
46
|
+
@macro ||= underscore(self.class).to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
# Borrowed from ActiveSupport::Inflector
|
50
|
+
def underscore(camel_cased_word)
|
51
|
+
word = camel_cased_word.to_s.dup
|
52
|
+
word = word.split('::').last
|
53
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
54
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
55
|
+
word.tr!("-", "_")
|
56
|
+
word.downcase!
|
57
|
+
word
|
58
|
+
end
|
59
|
+
|
60
|
+
def attributes
|
61
|
+
[self.attribute]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Validatable::ClassMethods.class_eval do
|
68
|
+
include Validatable::ActiveModelInterface::ClassMethods
|
69
|
+
end
|
70
|
+
|
71
|
+
Validatable.class_eval do
|
72
|
+
include Validatable::ActiveModelInterface::InstanceMethods
|
73
|
+
end
|
74
|
+
|
75
|
+
Validatable::ValidationBase.class_eval do
|
76
|
+
include Validatable::ActiveModelInterface::ValidationBase
|
77
|
+
end
|
78
|
+
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validatable-active_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian Cardarella
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-06 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: durran-validatable
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
- 1
|
34
|
+
version: 2.0.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: ruby-debug
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - "="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7712058
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 0
|
63
|
+
- 0
|
64
|
+
- rc
|
65
|
+
version: 2.0.0.rc
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: bourne
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: activesupport
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - "="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 19
|
91
|
+
segments:
|
92
|
+
- 2
|
93
|
+
- 3
|
94
|
+
- 8
|
95
|
+
version: 2.3.8
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id005
|
98
|
+
description: ActiveModel Interface for validatable
|
99
|
+
email: bcardarella@gmail.com
|
100
|
+
executables: []
|
101
|
+
|
102
|
+
extensions: []
|
103
|
+
|
104
|
+
extra_rdoc_files:
|
105
|
+
- LICENSE
|
106
|
+
- README.markdown
|
107
|
+
files:
|
108
|
+
- LICENSE
|
109
|
+
- README.markdown
|
110
|
+
- lib/validatable/active_model.rb
|
111
|
+
has_rdoc: true
|
112
|
+
homepage: http://github.com/bcardarella/validatable-active_model
|
113
|
+
licenses: []
|
114
|
+
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options:
|
117
|
+
- --charset=UTF-8
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
requirements: []
|
139
|
+
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.3.7
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: ActiveModel Interface for validatable
|
145
|
+
test_files: []
|
146
|
+
|