formkeeper 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/formkeeper.rb CHANGED
@@ -234,6 +234,40 @@ module FormKeeper
234
234
  end
235
235
  end
236
236
 
237
+ class Email < Base
238
+
239
+ # borrowed from
240
+ # http://blog.everqueue.com/chiba/2009/03/22/163/
241
+ def build_regexp
242
+ wsp = '[\x20\x09]'
243
+ vchar = '[\x21-\x7e]'
244
+ quoted_pair = "\\\\(?:#{vchar}|#{wsp})"
245
+ qtext = '[\x21\x23-\x5b\x5d-\x7e]'
246
+ qcontent = "(?:#{qtext}|#{quoted_pair})"
247
+ quoted_string = "\"#{qcontent}*\""
248
+ atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]'
249
+ dot_atom_text = "#{atext}+(?:[.]#{atext}+)*"
250
+ dot_atom = dot_atom_text
251
+ local_part = "(?:#{dot_atom}|#{quoted_string})"
252
+ domain = dot_atom
253
+ addr_spec = "#{local_part}[@]#{domain}"
254
+ dot_atom_loose = "#{atext}+(?:[.]|#{atext})*"
255
+ local_part_loose = "(?:#{dot_atom_loose}|#{quoted_string})"
256
+ addr_spec_loose = "#{local_part_loose}[@]#{domain}"
257
+ addr_spec_loose
258
+ end
259
+
260
+ def regexp
261
+ @regexp ||= build_regexp
262
+ end
263
+
264
+ def validate(value, arg)
265
+ r = ::Regexp.new('^' + regexp + '$')
266
+ value =~ r
267
+ end
268
+
269
+ end
270
+
237
271
  class Length < Base
238
272
  def validate(value, arg)
239
273
  l = value.length
@@ -662,6 +696,7 @@ module FormKeeper
662
696
  register_constraint :alnum, Constraint::Alnum.new
663
697
  register_constraint :alnum_space, Constraint::AlnumSpace.new
664
698
  register_constraint :uri, Constraint::URI.new
699
+ register_constraint :email, Constraint::Email.new
665
700
  register_constraint :length, Constraint::Length.new
666
701
  register_constraint :bytesize, Constraint::ByteSize.new
667
702
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: 467354677147035923
73
+ hash: 1336204735364772822
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 467354677147035923
82
+ hash: 1336204735364772822
83
83
  requirements: []
84
84
  rubyforge_project:
85
85
  rubygems_version: 1.8.24