effective_trash 0.2.5 → 0.2.6

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: 92e6355d34b1b5d1e73b50589906cfe539315aa7
4
- data.tar.gz: 5aa4eb0e2378f874b5d332fcfb64c44d688994c5
3
+ metadata.gz: 9aa7496caf63e3f09ad0778be9ef6c6b4a8667cd
4
+ data.tar.gz: af51ec535165f1a72c6f1bcf930f4761033bbed3
5
5
  SHA512:
6
- metadata.gz: 13c35c0f114774263e289ed237ffa8a5827753df1030fc0b3b4486de5f1a9b0456df8a1e921beb3fcf0d4375742fd935cd7901fa0fc2fb51586c20596147e093
7
- data.tar.gz: 624af54a2026c9aed71a2a9d3b5a750d0be980641829265635882f6f71f84533da1d6331fd9fb1d983a1daa213ffd5091d90e389d5550cf2e4119897ffa50040
6
+ metadata.gz: b8cf68d4f4fb439e7b99d6c687d93ac6def8e81707b26903d0de556defa9098c1953ca0ec2ce40c8d2a05f056f51582b179a799c13f4905c34df20e284deb9b6
7
+ data.tar.gz: 88dede0f9ca2cb31a9b0a75273fecf8d5db4551768718b0e2c22f89bade54748caa5c3857b3804af2b6550ab507672e19292bc1639fe13d3054006d3620f6960
@@ -26,10 +26,8 @@ module Effective
26
26
  self[:details] || {}
27
27
  end
28
28
 
29
- # So this is a Trash item
30
- # When we delete ourselves, we restore this trash item first
31
- def restore!
32
- raise 'no attributes to restore from' unless details.kind_of?(Hash) && details[:attributes].present?
29
+ def to_object
30
+ raise 'no attributes to consider' unless details.kind_of?(Hash) && details[:attributes].present?
33
31
 
34
32
  resource = Effective::Resource.new(trashed_type)
35
33
  object = trashed_type.constantize.new(details[:attributes])
@@ -37,15 +35,20 @@ module Effective
37
35
  resource.nested_resources.each do |association|
38
36
  if details[association.name].present? && object.respond_to?("#{association.name}_attributes=")
39
37
  nested_attributes = details[association.name].inject({}) do |h, (index, nested)|
40
- h[index] = nested[:attributes].except('id', association.inverse_of.foreign_key); h
38
+ h[index] = nested[:attributes].except('id', association.inverse_of&.foreign_key); h
41
39
  end
42
40
 
43
41
  object.send("#{association.name}_attributes=", nested_attributes)
44
42
  end
45
43
  end
46
44
 
47
- object.save!(validate: false)
48
- destroy!
45
+ object
46
+ end
47
+
48
+ # So this is a Trash item
49
+ # When we delete ourselves, we restore this trash item first
50
+ def restore!
51
+ to_object.save!(validate: false)
49
52
  end
50
53
 
51
54
  end
@@ -1,8 +1,6 @@
1
1
  .panel.panel-default
2
2
  .panel-body
3
- %p
4
- %span.label.label-default= trash
5
- = trash.trashed_to_s
3
+ %p= trash.trashed_to_s
6
4
 
7
5
  - if trash.trashed_extra.present?
8
6
  %p= trash.trashed_extra
@@ -1,3 +1,3 @@
1
1
  module EffectiveTrash
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.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.2.5
4
+ version: 0.2.6
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: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails