sequel_sexy_validations 0.2.2 → 0.2.3
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -12,14 +12,14 @@ module Sequel
|
|
12
12
|
module ClassMethods
|
13
13
|
def validates(attribute = nil, validations = nil, &block)
|
14
14
|
if validations
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
if validations[:if]
|
16
|
+
validations[:if] = [validations[:if]] unless validations[:if].is_a?(Array)
|
17
|
+
implement_special_validation_conditions!(validations[:if])
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if validations[:unless]
|
21
|
+
validations[:unless] = [validations[:unless]] unless validations[:unless].is_a?(Array)
|
22
|
+
implement_special_validation_conditions!(validations[:unless])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -34,6 +34,23 @@ module Sequel
|
|
34
34
|
super
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def implement_special_validation_conditions!(validations)
|
41
|
+
validations.each_with_index do |validation, i|
|
42
|
+
case validation
|
43
|
+
when :new
|
44
|
+
validations[i] = lambda do |record, attribute|
|
45
|
+
record.new?
|
46
|
+
end
|
47
|
+
when :changed
|
48
|
+
validations[i] = lambda do |record, attribute|
|
49
|
+
record.changed_columns.include?(attribute)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
37
54
|
end
|
38
55
|
|
39
56
|
module InstanceMethods
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "sexy_validations/validators/presence"
|
3
|
+
|
4
|
+
module Sequel
|
5
|
+
module Plugins
|
6
|
+
module SexyValidations
|
7
|
+
module Validators
|
8
|
+
class Presence < ::SexyValidations::Validators::Presence
|
9
|
+
def self.validate(model, attribute, value, options)
|
10
|
+
real_value = case value.class.name
|
11
|
+
when "Sequel::Plugins::Paperclip::Attachment"
|
12
|
+
value.queued_file
|
13
|
+
else
|
14
|
+
value
|
15
|
+
end
|
16
|
+
super(model, attribute, real_value, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sequel_sexy_validations}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Corin Langosch"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-29}
|
13
13
|
s.description = %q{Sequel plugin which provides sexy validations for model.}
|
14
14
|
s.email = %q{info@netskin.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/sequel_sexy_validations.rb",
|
27
|
+
"lib/sequel_sexy_validations/validators/presence.rb",
|
27
28
|
"lib/sequel_sexy_validations/validators/uniqueness.rb",
|
28
29
|
"sequel_sexy_validations.gemspec",
|
29
30
|
"spec/sequel_sexy_validations_spec.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Corin Langosch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-29 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- Rakefile
|
65
65
|
- VERSION
|
66
66
|
- lib/sequel_sexy_validations.rb
|
67
|
+
- lib/sequel_sexy_validations/validators/presence.rb
|
67
68
|
- lib/sequel_sexy_validations/validators/uniqueness.rb
|
68
69
|
- sequel_sexy_validations.gemspec
|
69
70
|
- spec/sequel_sexy_validations_spec.rb
|