effective_trash 0.3.1 → 0.3.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: b542e2929ae9716df6b09a9a482657b25fcebf17
4
- data.tar.gz: caf41ba9a378738c5916d969c45280f4c33c3bd9
3
+ metadata.gz: fd64b9818e00706023f8e7756ceaa5dcdfd6ef01
4
+ data.tar.gz: afd0d089858ce9067dfc015e4df141d55f808411
5
5
  SHA512:
6
- metadata.gz: a7c3a8f18344b204dadef5bb6225a24d0857dd4180803cc3e5302e7e6a07c941b626b2ecec06a7568c8dbe0ccede8c9acf8f8be50e82687d0ed2c50305dae579
7
- data.tar.gz: 4ff53ef056b81d4f18fd333aeddf446f500172c261fc92878074ac51c4bd2bda818b30241811e342b6a02a0c552bf131ebd8441cd157ac3055bb583302876365
6
+ metadata.gz: b6c67bc50bda291c33831e20fc0a2680929abe593d2d6515a2311ff9867cb6492901a159467b4e3261bf326488d4432516c3548f92d3a3fd43fba8a85484dc72
7
+ data.tar.gz: 9b5d9185ff36a93efacd8eca43777901e89ce07dfad4cbe19f1747edd4fc086b0656ac080f6a049d6dfdb8709d71dd5b923fef20c6252d0a5ab89d0c92da6028
data/README.md CHANGED
@@ -58,6 +58,10 @@ It also serializes the attributes of any `belongs_to`, `has_one`, and `has_many`
58
58
 
59
59
  Restoring only works with the single base object right now.
60
60
 
61
+ `acts_as_trashable include_associated: false` for cheaper trashes that don't to_s every object.
62
+
63
+ `acts_as_trashable include_nested: false` will ignore any nested_attributes, but careful you can lose data when true.
64
+
61
65
  ## Routes
62
66
 
63
67
  Visit `/trash`, or `/admin/trash` for an interface to view and restore Trash.
@@ -24,7 +24,9 @@ module ActsAsTrashable
24
24
  acts_as_trashable_options = {
25
25
  only: Array(@acts_as_trashable_options[:only]).map { |attribute| attribute.to_s },
26
26
  except: Array(@acts_as_trashable_options[:except]).map { |attribute| attribute.to_s },
27
- additionally: Array(@acts_as_trashable_options[:additionally]).map { |attribute| attribute.to_s }
27
+ additionally: Array(@acts_as_trashable_options[:additionally]).map { |attribute| attribute.to_s },
28
+ include_associated: @acts_as_trashable_options.fetch(:include_associated, true),
29
+ include_nested: @acts_as_trashable_options.fetch(:include_nested, true)
28
30
  }
29
31
 
30
32
  self.send(:define_method, :acts_as_trashable_options) { acts_as_trashable_options }
@@ -44,12 +44,18 @@ module EffectiveTrash
44
44
  # Trash it - Does not delete the original object.
45
45
  # This is run in a before_destroy, or through a script.
46
46
  def self.trash!(obj)
47
+ args = if obj.respond_to?(:acts_as_trashable_options)
48
+ obj.acts_as_trashable_options.slice(:include_associated, :include_nested)
49
+ else
50
+ { include_associated: true, include_nested: true }
51
+ end
52
+
47
53
  trash = Effective::Trash.new(
48
54
  trashed: obj,
49
55
  user: EffectiveTrash.current_user,
50
56
  trashed_to_s: obj.to_s,
51
57
  trashed_extra: (trashed_extra if obj.respond_to?(:trashed_extra)),
52
- details: Effective::Resource.new(obj).instance_attributes
58
+ details: Effective::Resource.new(obj).instance_attributes(args)
53
59
  ).save!
54
60
  end
55
61
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveTrash
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_trash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2018-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails