invisible_record 0.1.5 → 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/model.rb +8 -7
- 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
@@ -1,29 +1,30 @@
|
|
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
|
7
8
|
module Model
|
8
9
|
def acts_as_invisible(**options)
|
9
10
|
options.deep_symbolize_keys!
|
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?
|
16
21
|
true
|
17
22
|
end
|
18
|
-
|
19
|
-
def without_deleted
|
20
|
-
where(@_deleted_timestamp_attr => nil)
|
21
|
-
end
|
22
23
|
end
|
23
24
|
|
24
|
-
Helper.define_hidden_attributes self, deleted_ts_attr:
|
25
|
+
Helper.define_hidden_attributes self, deleted_ts_attr: deleted_timestamp_attr
|
25
26
|
|
26
|
-
Helper.define_actions self, deleted_ts_attr:
|
27
|
+
Helper.define_actions self, deleted_ts_attr: deleted_timestamp_attr
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -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:
|