simple_model 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_model.rb +1 -0
- data/lib/simple_model/attributes.rb +2 -1
- data/lib/simple_model/validation.rb +4 -3
- data/lib/simple_model/version.rb +1 -1
- metadata +3 -3
data/lib/simple_model.rb
CHANGED
@@ -53,10 +53,11 @@ module SimpleModel
|
|
53
53
|
|
54
54
|
module ClassMethods
|
55
55
|
def has_attributes(*attrs)
|
56
|
+
options = attrs.extract_options!
|
56
57
|
attrs.each do |attr|
|
57
58
|
|
58
59
|
attr_reader attr
|
59
|
-
|
60
|
+
define_reader_with_options(attr,options)
|
60
61
|
define_method("#{attr.to_s}=") do |val|
|
61
62
|
instance_variable_set("@#{attr}", val)
|
62
63
|
attributes[attr] = val
|
@@ -26,6 +26,7 @@ module SimpleModel
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
29
30
|
def validates_length_of(*attr_names)
|
30
31
|
options = attr_names.extract_options!
|
31
32
|
|
@@ -34,9 +35,9 @@ module SimpleModel
|
|
34
35
|
|
35
36
|
att_method = send(attr)
|
36
37
|
unless att_method.blank?
|
37
|
-
errors.add(attr,(options[:message].blank? ? "must equal #{options[:
|
38
|
-
errors.add(attr,(options[:message].blank? ? "cannot have more than #{options[:
|
39
|
-
errors.add(attr,(options[:message].blank? ? "cannot have less than #{options[:
|
38
|
+
errors.add(attr,(options[:message].blank? ? "must equal #{options[:is]} characters in length." : options[:message])) if options[:is] && att_method.to_s.length != options[:is]
|
39
|
+
errors.add(attr,(options[:message].blank? ? "cannot have more than #{options[:maximum]} characters in length." : options[:message])) if options[:maximum] && att_method.to_s.length > options[:maximum]
|
40
|
+
errors.add(attr,(options[:message].blank? ? "cannot have less than #{options[:minimum]} characters in length." : options[:message])) if options[:minimum] && att_method.to_s.length < options[:minimum]
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
data/lib/simple_model/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua T Mckinney
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-02-03 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|