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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/invisible_record/helper.rb +8 -3
- data/lib/invisible_record/model.rb +5 -0
- data/lib/invisible_record/scopes.rb +21 -0
- data/lib/invisible_record/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348e376c69c70a25be9552144601bb87c486d4c43da5f1d7d0baa9ec1e64b459
|
4
|
+
data.tar.gz: 4880ab1e4c89a1525a529da2004b5147fa918241f97a17966871974270ac8368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce93f839707533489f85284cd4efdd2a6f70d418541e535bcb9821ce2247c3730e25b053a3289d804784d299f51929a9629495d27f2cf9858e04a98d8216405
|
7
|
+
data.tar.gz: 342fd0ecec940b99e213318255ffc2259a43cb295c13f0894649f769042e2e74ffcabed14a3324dcd11db487fe0b4169517570253771cec5113595d305313d00
|
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
|
@@ -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
|
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.
|
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-
|
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:
|