invisible_record 0.1.2 → 0.2.0

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: 83ac4450dcab5420d45df80a3b43cc4832c9aa65fd9d7203b8c5a7d2190bd591
4
- data.tar.gz: f3fe66959227813ce9f5e29c230ee385472aae5e041012b0e60033f88352ab9d
3
+ metadata.gz: 348e376c69c70a25be9552144601bb87c486d4c43da5f1d7d0baa9ec1e64b459
4
+ data.tar.gz: 4880ab1e4c89a1525a529da2004b5147fa918241f97a17966871974270ac8368
5
5
  SHA512:
6
- metadata.gz: e1a71ee0832cd81b8c00657f08ce83e3fa08ac412cdb562b2548c261f7720636f6a8e59a38f24912b1dc4daf8b1cb0274696ab42bcfa85392fbf55687330658f
7
- data.tar.gz: c5cd6aec9d2204a15b592938f12063231ecdd5f048a80683072a3ad43469a70231d945a184fc4031f44e63bda5b90582438f0e528d2371ce69484ea8b0ee656d
6
+ metadata.gz: 8ce93f839707533489f85284cd4efdd2a6f70d418541e535bcb9821ce2247c3730e25b053a3289d804784d299f51929a9629495d27f2cf9858e04a98d8216405
7
+ data.tar.gz: 342fd0ecec940b99e213318255ffc2259a43cb295c13f0894649f769042e2e74ffcabed14a3324dcd11db487fe0b4169517570253771cec5113595d305313d00
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invisible_record (0.1.2)
4
+ invisible_record (0.2.0)
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "invisible_record/helper"
4
+ require "invisible_record/scopes"
4
5
 
5
6
  module InvisibleRecord
6
7
  # Add invisible behavior to an ActiveRecord Model
@@ -10,6 +11,10 @@ module InvisibleRecord
10
11
  deleted_timestamp_attr = options[:deleted_timestamp_attribute] || "deleted_at"
11
12
  raise "Only call acts_as_invisible once per model" if respond_to?(:invisible_record_model?)
12
13
 
14
+ include Scopes
15
+
16
+ define_default_scopes(deleted_ts_attr: deleted_timestamp_attr)
17
+
13
18
  class_eval do
14
19
  class << self
15
20
  def invisible_record_model?
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InvisibleRecord
4
+ # Define scopes for the invisible record
5
+ module Scopes
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ # Define methods for Scopes
11
+ module ClassMethods
12
+ protected
13
+
14
+ def define_default_scopes(deleted_ts_attr:)
15
+ default_scope { where(deleted_ts_attr => nil) }
16
+ scope :include_deleted, -> { unscoped.all }
17
+ scope :deleted, -> { unscoped.where.not(deleted_ts_attr => nil) }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InvisibleRecord
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
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.2
4
+ version: 0.2.0
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-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -92,6 +92,7 @@ files:
92
92
  - lib/invisible_record.rb
93
93
  - lib/invisible_record/helper.rb
94
94
  - lib/invisible_record/model.rb
95
+ - lib/invisible_record/scopes.rb
95
96
  - lib/invisible_record/version.rb
96
97
  homepage: https://github.com/FirstRootInc/invisible-record
97
98
  licenses: