better_record 0.10.3 → 0.10.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 868f2ca1bb72db17669260a1d1ef913960d92f6f91c75ea48dcaa8f0bb5d1000
4
- data.tar.gz: 1d504c0352fe3e2bbf64b5a0bfc027ce6c6de76e959cc58f62ee06949b6abcd9
3
+ metadata.gz: c0869b2f98d02a23adb72e8b4bd858808b762192ebbb953c84807d8f462aa2da
4
+ data.tar.gz: 9ed06a0ca435e62a9ed2f66cb8b8164fa89d26688128cfed4b8f83ee0899e535
5
5
  SHA512:
6
- metadata.gz: 330ebdd9bd1c8c1772d03290236705affbedb1f45c3fa7b99cc6b365365541cbe2d9afef7119d3fc862ab412d62ec1e89199cdaf8eba5fb21a94f6c531b1a854
7
- data.tar.gz: c502594671fcfa886bf481366121ffa568d5bf19ceef39a393c5ab66e9ababdfc686300f6320cc4c9426c181de7e59e740c3df819b5736c2f0f2ac285f3aa61d
6
+ metadata.gz: 1fb15f3111386f6ebef1516b61fe397976b29d9f2f87400ff311bfc5331c6a7371bfcc06ff011f3687ba273c856fbaeea5889b32f778360a06c56065b3ce381a
7
+ data.tar.gz: 2cfe923acd81309fb2bce64d01d85e9b8bca89ace312aeb3400bbbb7c34a6f05b9f86222706503c801c13780f6e1884325ac928c310695c2fd10e207b23567d9
@@ -32,6 +32,7 @@ module BetterRecord
32
32
  # == Attributes ===========================================================
33
33
  attribute :"new_#{password_field}", :text
34
34
  attribute :"new_#{password_field}_confirmation", :text
35
+ attribute :"clear_#{password_field}", :boolean
35
36
 
36
37
  # == Extensions ===========================================================
37
38
 
@@ -65,6 +66,15 @@ module BetterRecord
65
66
  end
66
67
  private :"#{password_field}="
67
68
 
69
+ define_method :"clear_#{password_field}=" do |value|
70
+ if value && (value.to_sym == :clear)
71
+ write_attribute password_field, (self.persisted? ? 'CLEAR_EXISTING_PASSWORD_FOR_ROW' : nil)
72
+ __send__ :"new_#{password_field}", nil
73
+ __send__ :"new_#{password_field}_confirmation", nil
74
+ end
75
+ true
76
+ end
77
+
68
78
  define_method :"require_#{password_field}_confirmation" do
69
79
  tmp_new_pwd = __send__ :"new_#{password_field}"
70
80
  tmp_new_confirmation = __send__ :"new_#{password_field}_confirmation"
@@ -41,7 +41,11 @@ module BetterRecord
41
41
  AND (
42
42
  (TG_OP = 'INSERT') OR ( NEW.#{password_col} IS DISTINCT FROM OLD.#{password_col} )
43
43
  ) THEN
44
- NEW.#{password_col} = hash_password(NEW.#{password_col});
44
+ IF (NEW.#{password_col} IS DISTINCT FROM 'CLEAR_EXISTING_PASSWORD_FOR_ROW') THEN
45
+ NEW.#{password_col} = hash_password(NEW.#{password_col});
46
+ ELSE
47
+ NEW.#{password_col} = NULL;
48
+ END IF;
45
49
  ELSE
46
50
  IF (TG_OP IS DISTINCT FROM 'INSERT') THEN
47
51
  NEW.#{password_col} = OLD.#{password_col};
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BetterRecord
4
- VERSION = '0.10.3'
4
+ VERSION = '0.10.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2018-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails