invisible_record 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/invisible_record.iml +29 -29
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/invisible_record/helper.rb +4 -1
- 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: 10509192fe474e4508b2426838c2482969f20a0e7dae34d1a3276b564df125e4
|
4
|
+
data.tar.gz: 1bbc70f05d88a28582b03b3743c0c98243b0e22ebe203bd7355f4865edc399cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db212abf77c4cf18b4f8f0e8b37cc3ee4d0c291a37d0571375978f08cc6a5fd0a0988d3b9e3fd74c07823d30400fb880e38ae4f27f392e11baafe0b20894080e
|
7
|
+
data.tar.gz: f4c8b9de28a9636187a77595f0329dedf5e830a145a9063493c51e294f9636b42be5fe3347d11b39a69d799836a89bc9c6f9d18a47223bc6b687e7c21b3958b0
|
data/.idea/invisible_record.iml
CHANGED
@@ -9,36 +9,36 @@
|
|
9
9
|
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
10
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
11
|
</content>
|
12
|
-
<orderEntry type="jdk" jdkName="
|
12
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-3.0.2" jdkType="RUBY_SDK" />
|
13
13
|
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="activemodel (v6.1.3,
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="activerecord (v6.1.3,
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.3,
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2,
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.27,
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9,
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4,
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.11,
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4,
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0,
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0,
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0,
|
26
|
-
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6,
|
27
|
-
<orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4,
|
28
|
-
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1,
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5,
|
30
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0,
|
31
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1,
|
32
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1,
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2,
|
34
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.3,
|
35
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.22.3,
|
36
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.13.0,
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0,
|
38
|
-
<orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.4.2,
|
39
|
-
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4,
|
40
|
-
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0,
|
41
|
-
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.1,
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="activemodel (v6.1.3, RVM: ruby-3.0.2) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord (v6.1.3, RVM: ruby-3.0.2) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.3, RVM: ruby-3.0.2) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-3.0.2) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.27, RVM: ruby-3.0.2) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, RVM: ruby-3.0.2) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, RVM: ruby-3.0.2) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.11, RVM: ruby-3.0.2) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, RVM: ruby-3.0.2) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-3.0.2) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4, RVM: ruby-3.0.2) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, RVM: ruby-3.0.2) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, RVM: ruby-3.0.2) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, RVM: ruby-3.0.2) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, RVM: ruby-3.0.2) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, RVM: ruby-3.0.2) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.3, RVM: ruby-3.0.2) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.22.3, RVM: ruby-3.0.2) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.13.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.4.2, RVM: ruby-3.0.2) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, RVM: ruby-3.0.2) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, RVM: ruby-3.0.2) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.1, RVM: ruby-3.0.2) [gem]" level="application" />
|
42
42
|
</component>
|
43
43
|
<component name="RakeTasksCache">
|
44
44
|
<option name="myRootTask">
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -32,7 +32,10 @@ module InvisibleRecord
|
|
32
32
|
def self.define_hidden_attributes(klass, deleted_ts_attr:)
|
33
33
|
klass.attribute_names.each do |attribute|
|
34
34
|
klass.define_method attribute do |*_args|
|
35
|
-
|
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
|
36
39
|
|
37
40
|
if attributes[deleted_ts_attr].present?
|
38
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, -> { unscope(where: deleted_ts_attr.to_sym) }
|
17
|
+
scope :deleted, -> { unscope(where: deleted_ts_attr.to_sym).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.1
|
4
|
+
version: 0.2.1
|
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
|
+
date: 2021-12-02 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:
|