sexy_validations 0.1.0 → 0.2.0

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.1.0
1
+ 0.2.0
@@ -36,12 +36,24 @@ module SexyValidations
36
36
 
37
37
  def validates(attribute = nil, validations = nil, &block)
38
38
  if validations
39
+ condition = nil
40
+
41
+ if validations[:if]
42
+ condition = validations.delete(:if)
43
+ end
44
+
45
+ if validations[:unless]
46
+ ref = validations.delete(:unless)
47
+ condition = lambda { |model| !ref.call(model) }
48
+ end
49
+
39
50
  validations.each_pair do |validator, options|
40
51
  klass = load_validator(validator)
41
52
  self.validations << {
42
53
  :attribute => attribute,
43
54
  :validator => klass,
44
55
  :options => options,
56
+ :condition => condition,
45
57
  }
46
58
  end
47
59
  else
@@ -64,6 +76,9 @@ module SexyValidations
64
76
  validations.each do |validation|
65
77
  valid = case
66
78
  when validation[:validator]
79
+ if validation[:condition]
80
+ next unless validation[:condition].call(self)
81
+ end
67
82
  if errors[validation[:attribute]].empty?
68
83
  validation[:validator].validate(self, validation[:attribute], send(validation[:attribute]), validation[:options])
69
84
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sexy_validations}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
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-10}
12
+ s.date = %q{2010-09-14}
13
13
  s.description = %q{Module which provides sexy validations for models.}
14
14
  s.email = %q{info@netskin.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
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-10 00:00:00 +01:00
17
+ date: 2010-09-14 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency