ardm 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ardm/ar/validations.rb +35 -9
- data/lib/ardm/dm.rb +6 -1
- data/lib/ardm/version.rb +1 -1
- metadata +2 -2
data/lib/ardm/ar/validations.rb
CHANGED
@@ -15,9 +15,13 @@ module Ardm
|
|
15
15
|
|
16
16
|
if Hash === fields.last
|
17
17
|
ar = fields.pop.dup
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
w = Array(ar.delete(:when)).first
|
19
|
+
if w && [:create, :update].include?(w)
|
20
|
+
ar[:on] = w
|
21
|
+
end
|
22
|
+
ar[:maximum] = ar.delete(:max) if ar[:max]
|
23
|
+
ar[:minimum] = ar.delete(:min) if ar[:min]
|
24
|
+
ar[:in] = ar.delete(:set) if ar[:set]
|
21
25
|
|
22
26
|
removed = ar.slice!(*keep)
|
23
27
|
unless removed.empty?
|
@@ -40,7 +44,19 @@ module Ardm
|
|
40
44
|
|
41
45
|
def validates_presence_of(*fields)
|
42
46
|
fields, options = Ardm::Ar::Validations.extract_options(fields)
|
43
|
-
|
47
|
+
|
48
|
+
boolean_fields, non_boolean_fields = fields.partition { |f| self.properties[f.to_sym].is_a?(Ardm::Property::Boolean) }
|
49
|
+
|
50
|
+
if non_boolean_fields.any?
|
51
|
+
validates(*non_boolean_fields, presence: options)
|
52
|
+
end
|
53
|
+
|
54
|
+
if boolean_fields.any?
|
55
|
+
if options.any?
|
56
|
+
$stderr.puts "validates_presence_of options ignored: #{options.inspect}"
|
57
|
+
end
|
58
|
+
validates(*boolean_fields, inclusion: {in: [true, false]})
|
59
|
+
end
|
44
60
|
end
|
45
61
|
|
46
62
|
def validates_length_of(*fields)
|
@@ -97,11 +113,21 @@ module Ardm
|
|
97
113
|
end
|
98
114
|
end
|
99
115
|
|
100
|
-
def validates_with_block(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
116
|
+
def validates_with_block(*args, &block)
|
117
|
+
options = args.extract_options!
|
118
|
+
attribute = args.shift
|
119
|
+
|
120
|
+
validate(options) do |_|
|
121
|
+
is_valid, message = instance_eval(&block)
|
122
|
+
|
123
|
+
unless is_valid
|
124
|
+
attribute ||= :base
|
125
|
+
|
126
|
+
if attribute.to_sym == :base
|
127
|
+
raise "message is blank #{args.inspect} #{self.inspect} #{block.inspect}" if message.blank?
|
128
|
+
end
|
129
|
+
|
130
|
+
errors.add(attribute, message)
|
105
131
|
end
|
106
132
|
end
|
107
133
|
end
|
data/lib/ardm/dm.rb
CHANGED
@@ -6,7 +6,12 @@ require 'ardm/dm/collection'
|
|
6
6
|
|
7
7
|
module Ardm
|
8
8
|
Record = Ardm::Dm::Record
|
9
|
-
|
9
|
+
begin
|
10
|
+
Validations = ::DataMapper::Validations
|
11
|
+
rescue NameError
|
12
|
+
# DataMapper::Validations might not be included.
|
13
|
+
end
|
14
|
+
|
10
15
|
SaveFailureError = ::DataMapper::SaveFailureError
|
11
16
|
RecordNotFound = ::DataMapper::ObjectNotFoundError
|
12
17
|
Property = ::DataMapper::Property
|
data/lib/ardm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ardm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-02-
|
13
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|