sequel_sexy_validations 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -4,6 +4,21 @@ module Sequel
4
4
  module SexyValidations
5
5
  module Validators
6
6
  class Uniqueness
7
+ def self.apply_scope_filter!(model, dataset, filter)
8
+ case filter
9
+ when Array
10
+ filter.each do |filter1|
11
+ apply_scope_filter!(model, dataset, filter1)
12
+ end
13
+ when Symbol
14
+ dataset.filter!(filter => model.send(filter))
15
+ when Proc
16
+ dataset.filter!(filter.call(model))
17
+ else
18
+ dataset.filter!(filter)
19
+ end
20
+ end
21
+
7
22
  def self.validate(model, attribute, value, options)
8
23
  return unless value
9
24
 
@@ -16,18 +31,7 @@ module Sequel
16
31
  options[:message] ||= "bereits vergeben"
17
32
 
18
33
  dataset = model.class.filter(~{:id => model.id}, {attribute => value})
19
- if options[:scope].is_a?(Array)
20
- options[:scope].each do |v|
21
- case v
22
- when Symbol
23
- dataset = dataset.filter(v => model.send(v))
24
- when Proc
25
- dataset = dataset.filter(v.call(model))
26
- else
27
- dataset = dataset.filter(v)
28
- end
29
- end
30
- end
34
+ apply_scope_filter!(model, dataset, options[:scope])
31
35
 
32
36
  unless dataset.empty?
33
37
  model.errors.add(attribute, options[:message])
@@ -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.5"
8
+ s.version = "0.2.6"
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-10-11}
12
+ s.date = %q{2010-11-13}
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 = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
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-10-11 00:00:00 +01:00
17
+ date: 2010-11-13 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency