simplificator-arext 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +16 -2
  2. data/lib/arext/validations.rb +5 -0
  3. metadata +1 -1
data/README CHANGED
@@ -17,16 +17,30 @@ validates_constraints make some assumptions (see below) and none of its behaviou
17
17
  * Adds validates_length_of for text columns with not null limit
18
18
 
19
19
  == validates_url
20
+ This validator adds the feature to validate urls with http and https protocols. It also include
21
+ portnumbers and any subdomains. Instead of a domain name, you can use ip address too (version 4).
20
22
 
21
23
  == validates_host
24
+ This validator adds the feature to validate a hostname. Instead of a hostname, you can
25
+ use ip address too (version 4).
26
+
22
27
 
23
28
  Example
24
29
  =======
25
-
30
+ == validates_constraints
26
31
  in your ActiveRecord class:
27
32
  validate_constraints(:attribute_name, :other_attribute_name)
28
33
  or
29
34
  validates_constraints() for all attributes
30
35
 
36
+ == validates_url
37
+ in your ActiveRecord class:
38
+ validates_url(:attribute)
39
+
40
+ == validates_host
41
+ in your ActiveRecord class:
42
+ validates_host(:attribute)
43
+
44
+
31
45
 
32
- Copyright (c) 2008 [name of plugin creator], released under the MIT license
46
+ Copyright (c) 2008 [simplificator gmbh], released under the MIT license
@@ -6,10 +6,15 @@ module Arext
6
6
  VALID_IP = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
7
7
  VALID_TLD = "[a-z]{2,5}"
8
8
  VALID_PORT = "(:[0-9]{1,5})?"
9
+
9
10
  def validates_url(attribute)
10
11
  validates_format_of(attribute, :with => /^#{VALID_PROTOCOLS}(#{VALID_HOST}\.#{VALID_TLD}|#{VALID_IP})#{VALID_PORT}(\/.*)?$/ix)
11
12
  end
12
13
 
14
+ def validates_host(attribute)
15
+ validates_format_of(attribute, :with => /^(#{VALID_HOST}\.#{VALID_TLD}|#{VALID_IP})$/)
16
+ end
17
+
13
18
 
14
19
  def validates_constraints(*attrs)
15
20
  attrs = column_names if attrs.blank?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-arext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simplificator GmbH