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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d70c2835b8f94f922df18a8bec3033a3dda6cfbcbbaf91520e6e4a34e2d32b4
4
- data.tar.gz: 30ef867d5777a27f1d8ba84e3ffa3b5108114a74ab28b50a0b29a168d660f11a
3
+ metadata.gz: e72f11da44f9f26a2bdb59d3ad4c141a03213c4879283ddb77fa16e0601ada23
4
+ data.tar.gz: b13ded4cf1304d6fc467c809cf1bc26a5ea3aa5b54e73214253178d26fbec4aa
5
5
  SHA512:
6
- metadata.gz: 6be0ba5a6f8deb7e4ccf880bfb97b73242003bc230bd1f46e55667abaa002d7caff73311cb30f4f68cc7af4d8682362108e5adc27a711da44064bec9313420e4
7
- data.tar.gz: 1fa1c02848b3d208b8f593a02f18e40992a6c27429c0fce2351b1914ec396c2855f06e250e7604f6ee205738687a6a1d89e9cfb46017f77a3953bd3e8f09d6a6
6
+ metadata.gz: b9badeaeb8d1ebb13053bc4112735e8d4f749bc87f248c508a437df2ecc42b387590c933bed268231b289458785932efbc1bc4ec75d2e7580431ef85c19a5e37
7
+ data.tar.gz: dc93e16661ad86b4191b4a237d51dfd581bf50fe050963b301324282373887048180089424eb8b32eb6b364bf18874ab4a15b30ea3ed8c31efb34c5d739a7764
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invisible_record (0.1.1)
4
+ invisible_record (0.1.5)
5
5
  activemodel (>= 5)
6
6
  activerecord (>= 5)
7
7
 
@@ -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 |*_args|
25
- soft_delete
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
- return attributes[deleted_ts_attr] if attribute == deleted_ts_attr
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
- deleted_timestamp_attr = options[:deleted_timestamp_attribute] || "deleted_at"
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: deleted_timestamp_attr
24
+ Helper.define_hidden_attributes self, deleted_ts_attr: @_deleted_timestamp_attr
21
25
 
22
- Helper.define_actions self, deleted_ts_attr: deleted_timestamp_attr
26
+ Helper.define_actions self, deleted_ts_attr: @_deleted_timestamp_attr
23
27
  end
24
28
  end
25
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InvisibleRecord
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.5"
5
5
  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.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-17 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel