-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
182 lines (141 loc) · 6.24 KB
/
README
File metadata and controls
182 lines (141 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Usage examples
# == Please Fill
class Article < ActiveRecord::Base
please_fill :title, :permalink, :body.as("your message")
end
"Please fill Title, Permalink and your message fields"
"Please fill Title field"
"Please fill Permalink field"
"Please fill your message"
# == Please Choose
class Address < ActiveRecord::Base
please_choose :country.as("your country"), :state
end
"Please choose your country and state"
"Please choose your country"
"Please choose state"
class Imaging < ActiveRecord::Base
please_choose "imagings:", :front_imaging.as("front"), :back_imaging.as("back")
end
"Please choose imagings: front and back"
# == Please Make Sure
class Address < ActiveRecord::Base
please_make_sure :zip, :as => "Zip code", :is => [
{ :numeric => { :greater_than => 0 } },
{ :length => 5 },
[:format, /0\d{4}/, "starts with zero"]
]
please_make_sure :zip.as("Zip code"), :is => [
:numeric.greater_than(0),
:length.equals(5),
:format.with(/0\d{4}/, "starts with zero")
]
please_make_sure :zip.as("Zip code").is(
:numeric.greater_than(0, ""),
:length.equals(5, "5 characters long"),
:format.with(/0\d{4}/, "starts with zero")
)
end
"Please make sure that Zip code is numeric, 5 characters long and starts with zero"
"Please make sure that Zip code 5 characters long and starts with zero"
"Please make sure that Zip code starts with zero"
class Adress < ActiveRecord::Base
please_fill :first_name, :last_name, :country.as("Your country"), :state.if(:country_has_state)
def country_has_state
["USA", "Canada"].include? country
end
end
# ==
class Person < ActiveRecord::Base
validates_acceptance_of :terms_of_service
validates_acceptance_of :eula, :message => "must be abided"
please_accept :terms_of_service
end
class Person < ActiveRecord::Base
validates_presence_of :first_name
validates_presence_of :country
please_fill :first_name
please_choose :county
end
class Person < ActiveRecord::Base
validates_uniqueness_of :login
validates_uniqueness_of :user_name, :scope => :account_id
validates_uniqueness_of :teacher_id, :scope => [:semester_id, :class_id]
make_sure :login.is(:uniq)
make_sure :login.is_uniq
make_sure :login, :is => [:uniq, {:case_sensitive => true }, "uniq (case sensitive)"]
make_sure :login, :is => [:uniq.case_sensitive("case sensitive uniq")]
make_sure :user_name, :is => :uniq.scope(:account_id)
make_sure :teacher_id, :is => :uniq.scope([:semester_id, :class_id], "uniq touple(teacher, semester, class)")
end
class Person < ActiveRecord::Base
validates_length_of :first_name, :maximum=>30
validates_length_of :last_name, :maximum=>30, :message=>"less than {{count}} if you don't mind"
validates_length_of :fax, :in => 7..32, :allow_nil => true
validates_length_of :phone, :in => 7..32, :allow_blank => true
validates_length_of :user_name, :within => 6..20, :too_long => "pick a shorter name", :too_short => "pick a longer name"
validates_length_of :fav_bra_size, :minimum => 1, :too_short => "please enter at least {{count}} character"
validates_length_of :smurf_leader, :is => 4, :message => "papa is spelled with {{count}} characters... don't play me."
validates_length_of :essay, :minimum => 100, :too_short => "Your essay must be at least {{count}} words."), :tokenizer => lambda {|str| str.scan(/\w+/) }
make_sure :first_name.has( :length.max(30) )
make_sure :last_name.lenght.max(30, "less than {{count}} if you don't mind")
make_sure :fax.has( length.in(7..32).or_nil )
make_sure :phone.length.in(7..32).or_blank
make_sure :user_name.is(
# :length.within(6..20, :too_short => "pick a shorter name", :too_long => "pick a longer name").
:length.within(6..20, "pick a shorter name", "pick a longer name").
)
make_sure :smurf_leader.length.is(4, "papa is spelled with {{count}} characters... don't play me.")
# min => too_short(message)
# max => too_long(message)
make_sure :essay.length.min(100, "Your essay must be at least {{count}} words.").
tokenizer( lambda {|str| str.scan(/\w+/) } )
end
class Person < ActiveRecord::Base
EMAIL_REGEXP = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates_presence_of :email
validates_uniqueness_of :email, :case_sensitive => true
validates_length_of :email, :in => 7..32
validates_format_of :email, :with => EMAIL_REGEXP
please_fill :email;
and_make_sure :email, :is => :uniq, [:length, 5..128] }, [:format, EMAIL_REGEXP]]
please_fill :email; and_make_sure :email.is(
:uniq.case_sensitive.scope(:account_id), :length.in(5..128), :format.with(EMAIL_REGEXP)
)
please_fill_and_make_sure :email.is(
:uniq.case_sensitive.scope(:account_id), :length.in(5..128), :format.with(EMAIL_REGEXP)
)
validates_presence_of :login
validates_uniqueness_of :login, :case_sensitive => true
validates_presence_of :email
validates_uniqueness_of :email, :scope => :account_id
validates_length_of :email, :in => 7..32
validates_format_of :email, :with => EMAIL_REGEXP
please_fill_and_make_sure :login.as("Username").is(:uniq.case_sensitive),
:email.is(
:uniq.scope(:account_id),
:length.in(5..128),
:format.with(EMAIL_REGEXP)
)
make_sure :login.as("Username").is(
:present, # :filled
:uniq.case_sensitive
),
:email.is(
:present, # :filled
:uniq.scope(:account_id),
:length.in(5..128),
:format.with(EMAIL_REGEXP)
)
end
class Person < ActiveRecord::Base
validates_inclusion_of :gender, :in => %w( m f ), :message => "woah! what are you then!??!!"
validates_inclusion_of :age, :in => 0..99
validates_inclusion_of :format, :in => %w( jpg gif png ), :message => "extension {{value}} is not included in the list"
please_make_sure :age.in(1..100)
please_choose :format.from(%w( jpg gif png ), "extention {{value}} is not included in the list")
end
class Person < ActiveRecord::Base
validates_numericality_of :value, :on => :create
please_make_sure :value.is(:numeric.less_than_or_equal_to(100))
end