invisible_record 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/invisible_record/helper.rb +8 -3
- data/lib/invisible_record/model.rb +7 -3
- data/lib/invisible_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e72f11da44f9f26a2bdb59d3ad4c141a03213c4879283ddb77fa16e0601ada23
|
4
|
+
data.tar.gz: b13ded4cf1304d6fc467c809cf1bc26a5ea3aa5b54e73214253178d26fbec4aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9badeaeb8d1ebb13053bc4112735e8d4f749bc87f248c508a437df2ecc42b387590c933bed268231b289458785932efbc1bc4ec75d2e7580431ef85c19a5e37
|
7
|
+
data.tar.gz: dc93e16661ad86b4191b4a237d51dfd581bf50fe050963b301324282373887048180089424eb8b32eb6b364bf18874ab4a15b30ea3ed8c31efb34c5d739a7764
|
data/Gemfile.lock
CHANGED
@@ -21,8 +21,10 @@ module InvisibleRecord
|
|
21
21
|
send(assign_timestamp, options[:datetime])
|
22
22
|
end
|
23
23
|
|
24
|
-
klass.define_method "soft_delete!" do |*
|
25
|
-
|
24
|
+
klass.define_method "soft_delete!" do |*args|
|
25
|
+
options = args.last || {}
|
26
|
+
options[:datetime] ||= DateTime.now
|
27
|
+
soft_delete(datetime: options[:datetime])
|
26
28
|
save!
|
27
29
|
end
|
28
30
|
end
|
@@ -30,7 +32,10 @@ module InvisibleRecord
|
|
30
32
|
def self.define_hidden_attributes(klass, deleted_ts_attr:)
|
31
33
|
klass.attribute_names.each do |attribute|
|
32
34
|
klass.define_method attribute do |*_args|
|
33
|
-
|
35
|
+
protected_attributes = ["id", deleted_ts_attr]
|
36
|
+
protected_attributes.each do |protected_attr_name|
|
37
|
+
return attributes[protected_attr_name] if attribute == protected_attr_name
|
38
|
+
end
|
34
39
|
|
35
40
|
if attributes[deleted_ts_attr].present?
|
36
41
|
nil
|
@@ -7,7 +7,7 @@ module InvisibleRecord
|
|
7
7
|
module Model
|
8
8
|
def acts_as_invisible(**options)
|
9
9
|
options.deep_symbolize_keys!
|
10
|
-
|
10
|
+
@_deleted_timestamp_attr = options[:deleted_timestamp_attribute] || "deleted_at"
|
11
11
|
raise "Only call acts_as_invisible once per model" if respond_to?(:invisible_record_model?)
|
12
12
|
|
13
13
|
class_eval do
|
@@ -15,11 +15,15 @@ module InvisibleRecord
|
|
15
15
|
def invisible_record_model?
|
16
16
|
true
|
17
17
|
end
|
18
|
+
|
19
|
+
def without_deleted
|
20
|
+
where(@_deleted_timestamp_attr => nil)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
|
-
Helper.define_hidden_attributes self, deleted_ts_attr:
|
24
|
+
Helper.define_hidden_attributes self, deleted_ts_attr: @_deleted_timestamp_attr
|
21
25
|
|
22
|
-
Helper.define_actions self, deleted_ts_attr:
|
26
|
+
Helper.define_actions self, deleted_ts_attr: @_deleted_timestamp_attr
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invisible_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Rejón
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|