protected_record 0.0.1 → 0.0.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: 5936b33d95c7b170f1c1f0a90dbb94ba3d5cddc5
4
- data.tar.gz: 4d6bbe694afa07f22a4b04e93fc6dc13fc9819a6
3
+ metadata.gz: 9b986b59a39e95c1cf010e1d832fe5e3b113a09b
4
+ data.tar.gz: 9aaf2d518fb70dc521b35fee444af5b745448ab7
5
5
  SHA512:
6
- metadata.gz: fd08a85e169ce3ebc9e47f0217fd031d90ef01b1330640113e6b39c1d57a071cb0de107863b5269e2b3904716976131e19b4c974a64773eede60efa33b6d30e4
7
- data.tar.gz: f5829512aba3077dc008b4fa47145ecda4c3f54713b50f679ef4f2d7f42da09c3043df93f1db0e1c3864e5a1b7fa6ba44444b05a40d2a771dd7c15147dde9f64
6
+ metadata.gz: e56a6564bf7007ab129daba444ff2d3e05416e0e0430203de47a6eee348ee42714bb3e0b939aaba998fef5ff48ffb9991f11d4d35e6be1709d50661440afd073
7
+ data.tar.gz: cc0a5f9563e9bb726611c8935d967f182136881060f28bd22604818c0150afde4eb9b828acbeecf86bbee452af3a6a4cec264a233d6b3836001e0f81713f90b3
@@ -3,13 +3,15 @@ module ProtectedRecord
3
3
  module ChangeFilter
4
4
  class Create < PayDirt::Base
5
5
  def initialize(options)
6
- load_options(:protected_keys, :protected_record, options) and validate_state
6
+ load_options(:protected_keys, :protected_record, options)
7
7
  end
8
8
 
9
9
  def execute!
10
- revert_protected_attrs
10
+ if @protected_record.changes.present?
11
+ revert_protected_attrs
12
+ end
11
13
 
12
- return PayDirt::Result.new(data: { change_request_record: @protected_record })
14
+ return PayDirt::Result.new(data: { change_request_record: @protected_record }, success: true)
13
15
  end
14
16
 
15
17
  private
@@ -20,14 +22,6 @@ module ProtectedRecord
20
22
  end
21
23
  end
22
24
  end
23
-
24
- protected
25
- def validate_state
26
- # If there are no changes, there's no need to do any filtering
27
- if !@protected_record.changes.present?
28
- raise ActiveRecord::ActiveRecordError.new(':protected_record not dirty')
29
- end
30
- end
31
25
  end
32
26
  end
33
27
  end
@@ -7,14 +7,17 @@ module ProtectedRecord
7
7
  record_class: ::ProtectedRecord::ChangeLog::Record
8
8
  }.merge!(options) if !options.has_key?(:record_class)
9
9
 
10
- load_options(:record_class, :user, :changed_object, options) and validate_state
10
+ load_options(:record_class, :user, :changed_object, options)
11
11
  end
12
12
 
13
13
  def execute!
14
+ if !@changed_object.previous_changes.present?
15
+ return PayDirt::Result.new(data: { change_log_record: @record }, success: true)
16
+ end
14
17
  initialize_change_log_record
15
18
 
16
19
  if @record.save
17
- return PayDirt::Result.new(data: { change_log_record: @record })
20
+ return PayDirt::Result.new(data: { change_log_record: @record }, success: true)
18
21
  else
19
22
  return PayDirt::Result.new(data: { change_log_record: @record }, success: false)
20
23
  end
@@ -27,14 +30,6 @@ module ProtectedRecord
27
30
  @record.recordable = @changed_object
28
31
  @record.observed_changes = ActiveSupport::JSON.encode(@changed_object.previous_changes)
29
32
  end
30
-
31
- protected
32
- def validate_state
33
- # What are we doing here, if not logging a change that has already happened?
34
- if !@changed_object.previous_changes.present?
35
- raise ActiveRecord::ActiveRecordError.new(':changed_object has no previous_changes')
36
- end
37
- end
38
33
  end
39
34
  end
40
35
  end
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  module ProtectedRecord
2
3
  module UseCase
3
4
  module ChangeRequest
@@ -7,7 +8,7 @@ module ProtectedRecord
7
8
  record_class: ::ProtectedRecord::ChangeRequest::Record
8
9
  }.merge!(options) if !options.has_key?(:record_class)
9
10
 
10
- load_options(:protected_keys, :record_class, :user, :protected_record, options) and validate_state
11
+ load_options(:protected_keys, :record_class, :user, :protected_record, options)
11
12
  end
12
13
 
13
14
  def execute!
@@ -16,7 +17,7 @@ module ProtectedRecord
16
17
  initialize_change_request_record
17
18
 
18
19
  if @record.save
19
- return PayDirt::Result.new(data: { change_request_record: @record })
20
+ return PayDirt::Result.new(data: { change_request_record: @record }, success: true)
20
21
  else
21
22
  return PayDirt::Result.new(data: { change_request_record: @record }, success: false)
22
23
  end
@@ -31,7 +32,7 @@ module ProtectedRecord
31
32
  end
32
33
 
33
34
  def requested_changes
34
- @dirty_object.changes.select do |key|
35
+ @protected_record.changes.select do |key|
35
36
  @protected_keys.map(&:to_s).include? key.to_s
36
37
  end
37
38
  end
@@ -45,15 +46,6 @@ module ProtectedRecord
45
46
 
46
47
  raise if @protected_keys.any? { |key| @protected_record.send("#{key}_changed?") }
47
48
  end
48
-
49
- protected
50
- def validate_state
51
- # If there are no changes, there's no need to make a request
52
- if !@dirty_object.changes.present?
53
- raise ActiveRecord::ActiveRecordError.new(':dirty_object not dirty')
54
- end
55
- end
56
-
57
49
  end
58
50
  end
59
51
  end
@@ -18,9 +18,9 @@ module ProtectedRecord
18
18
 
19
19
  # We are successful if all changes have been applied
20
20
  if !@protected_record.changes.present?
21
- return UseCase::Result.new(data: { updated: @protected_record })
21
+ return PayDirt::Result.new(data: { updated: @protected_record }, success: true)
22
22
  else
23
- return UseCase::Result.new({
23
+ return PayDirt::Result.new({
24
24
  data: { remaining_changes: @protected_record.changes },
25
25
  success: false
26
26
  })
@@ -63,7 +63,7 @@ module ProtectedRecord
63
63
  def log_changes
64
64
  log_result = @change_log.new(user: @user, changed_object: @protected_record).execute!
65
65
 
66
- result.successful? ? return : raise
66
+ log_result.successful? ? return : raise
67
67
  end
68
68
 
69
69
  protected
@@ -1,3 +1,3 @@
1
1
  module ProtectedRecord
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protected_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford