sequel-paranoid 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sequel/plugins/paranoid.rb +11 -4
  2. metadata +2 -2
@@ -10,7 +10,7 @@ module Sequel::Plugins
10
10
  :deleted_scope_name => :deleted,
11
11
  :non_deleted_scope_name => :present,
12
12
  :ignore_deletion_scope_name => :with_deleted,
13
- :set_default_scope => false
13
+ :enable_default_scope => false
14
14
  }.merge(options)
15
15
 
16
16
  model.instance_eval do
@@ -39,14 +39,21 @@ module Sequel::Plugins
39
39
  # Overwrite the "destroy" method.
40
40
  #
41
41
 
42
- define_method("destroy") do
42
+ define_method("destroy") do |*args|
43
+ destroy_options = args.first
44
+
43
45
  # call the before_destroy hook if present
44
46
  if self.respond_to?(:before_destroy)
45
47
  self.before_destroy
46
48
  end
47
49
 
48
50
  # set the deletion time
49
- self.deleted_at = Time.now
51
+ self.send("#{options[:deleted_at_field_name]}=", Time.now)
52
+
53
+ # set the deletion author
54
+ if options[:enable_deleted_by] && destroy_options && destroy_options[:deleted_by]
55
+ self.send("#{options[:deleted_by_field_name]}=", destroy_options[:deleted_by])
56
+ end
50
57
 
51
58
  # save the instance and call the after_destroy hook if present
52
59
  if save and self.respond_to?(:after_destroy)
@@ -74,7 +81,7 @@ module Sequel::Plugins
74
81
  # Inject the default scope that filters deleted entries.
75
82
  #
76
83
 
77
- if options[:set_default_scope]
84
+ if options[:enable_default_scope]
78
85
  set_dataset(self.send(options[:non_deleted_scope_name]))
79
86
  end
80
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  segments:
52
52
  - 0
53
- hash: 2232120226963572193
53
+ hash: 1230543720425849314
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements: