simplificator-arext 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +6 -1
- data/lib/arext/validations.rb +10 -0
- metadata +3 -3
data/README
CHANGED
@@ -3,7 +3,8 @@ Arext
|
|
3
3
|
|
4
4
|
Active Record Extensions.
|
5
5
|
|
6
|
-
|
6
|
+
=== Validations
|
7
|
+
== validates_constraints
|
7
8
|
This uses the information one can extract from ActiveRecord::ConnectionAdapter::Column
|
8
9
|
to add default validations. The text?, limit and type methods are used to guess what validations are to be added
|
9
10
|
validates_constraints make some assumptions (see below) and none of its behaviour is configurable.
|
@@ -15,6 +16,10 @@ validates_constraints make some assumptions (see below) and none of its behaviou
|
|
15
16
|
* Adds validates_inclusion_of(:in => [true, false]) for columns with not null constraints and :boolean type
|
16
17
|
* Adds validates_length_of for text columns with not null limit
|
17
18
|
|
19
|
+
== validates_url
|
20
|
+
|
21
|
+
== validates_host
|
22
|
+
|
18
23
|
Example
|
19
24
|
=======
|
20
25
|
|
data/lib/arext/validations.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
module Arext
|
2
2
|
module Validations
|
3
3
|
module ClassMethods
|
4
|
+
VALID_PROTOCOLS = "(http|https):\/\/"
|
5
|
+
VALID_HOST = "[a-z0-9]+([\-\.]{1}[a-z0-9]+)*"
|
6
|
+
VALID_IP = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
|
7
|
+
VALID_TLD = "[a-z]{2,5}"
|
8
|
+
VALID_PORT = "(:[0-9]{1,5})?"
|
9
|
+
def validates_url(attribute)
|
10
|
+
validates_format_of(attribute, :with => /^#{VALID_PROTOCOLS}(#{VALID_HOST}\.#{VALID_TLD}|#{VALID_IP})#{VALID_PORT}(\/.*)?$/ix)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
4
14
|
def validates_constraints(*attrs)
|
5
15
|
attrs = column_names if attrs.blank?
|
6
16
|
attrs.each do |attr|
|
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.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simplificator GmbH
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-02 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,7 +27,7 @@ files:
|
|
27
27
|
- lib/arext/validations.rb
|
28
28
|
- README
|
29
29
|
has_rdoc: false
|
30
|
-
homepage: http://
|
30
|
+
homepage: http://simplificator.com/en/lab
|
31
31
|
post_install_message:
|
32
32
|
rdoc_options: []
|
33
33
|
|