path_utilities 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 016c2c9cb836407b9f993c5fb039a63c49cad5b6
|
4
|
+
data.tar.gz: fd2283f919f9caa809f002f15ff2bce71542636a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 234decbe01ceb25ea6468248427c99cd1019eec971a3694b8ee3e788de6fe90fa6fbcd92f75cc6092cdde9564483b6921daefcec5911b7a8353520b7fc925ca5
|
7
|
+
data.tar.gz: a6e0670724b73f22a689e01a8c70f7ff47b195f7b694a281fbc7860350ba13d7fb23b105d2199a8473b15ae74e9582accbfa1ca98f96a6c6f2a98de9e3a95055
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module PathUtilities
|
2
|
+
module Form
|
3
|
+
module TrackingChanges
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def changes?(field)
|
7
|
+
form_field_value = send(field)
|
8
|
+
model_field_value = instance_model_for(field).send(field)
|
9
|
+
model_field_value != form_field_value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -19,7 +19,7 @@ module PathUtilities
|
|
19
19
|
# If we're inside an ActiveRecord class, and `model` isn't set, use the
|
20
20
|
# default behaviour of the validator.
|
21
21
|
#
|
22
|
-
elsif !
|
22
|
+
elsif !options[:model]
|
23
23
|
super
|
24
24
|
|
25
25
|
# Custom validator options. The validator can be called in any class, as
|
@@ -33,12 +33,16 @@ module PathUtilities
|
|
33
33
|
|
34
34
|
attribute = options[:attribute].to_sym if options[:attribute]
|
35
35
|
record = options[:model].new(attribute => value)
|
36
|
+
is_new_record = record_org.instance_model_for(attribute).new_record?
|
36
37
|
|
37
|
-
|
38
|
+
if is_new_record || record_org.changes?(attribute)
|
39
|
+
super
|
40
|
+
|
41
|
+
if record.errors.any?
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
record_org.errors.add(attribute_org, :taken,
|
44
|
+
options.except(:case_sensitive, :scope).merge(value: value))
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
data/lib/path_utilities/form.rb
CHANGED
@@ -9,12 +9,14 @@ module PathUtilities
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
autoload :UniquenessValidator, 'path_utilities/form/uniqueness_validator'
|
12
|
+
autoload :TrackingChanges, 'path_utilities/form/tracking_changes'
|
12
13
|
|
13
14
|
included do
|
14
15
|
include Virtus.model
|
15
16
|
extend ActiveModel::Naming
|
16
17
|
include ActiveModel::Conversion
|
17
18
|
include ActiveModel::Validations
|
19
|
+
include TrackingChanges
|
18
20
|
|
19
21
|
attr_reader :models_mapping
|
20
22
|
|
@@ -33,7 +35,9 @@ module PathUtilities
|
|
33
35
|
|
34
36
|
def validate(params)
|
35
37
|
self.class.fields.keys.each do |field|
|
36
|
-
|
38
|
+
if params[field].present?
|
39
|
+
send("#{field}=", params[field])
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
valid?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: path_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricard Forniol Agustí
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- bin/setup
|
170
170
|
- lib/path_utilities.rb
|
171
171
|
- lib/path_utilities/form.rb
|
172
|
+
- lib/path_utilities/form/tracking_changes.rb
|
172
173
|
- lib/path_utilities/form/uniqueness_validator.rb
|
173
174
|
- lib/path_utilities/form/uniqueness_validator/mongoid.rb
|
174
175
|
- lib/path_utilities/version.rb
|