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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ee54865fb6e434aab2b548042557c735a02ccef639c5baff053fd412751cfc8
4
- data.tar.gz: e708423f48672b3bcec32c6c65219ce9e4adb0956ccf8bf7897ebfae7eb0190a
3
+ metadata.gz: 10509192fe474e4508b2426838c2482969f20a0e7dae34d1a3276b564df125e4
4
+ data.tar.gz: 1bbc70f05d88a28582b03b3743c0c98243b0e22ebe203bd7355f4865edc399cf
5
5
  SHA512:
6
- metadata.gz: f86c3168c0814c91e7d1871b829436b567aa0f2cf3fcef0b8ab548aeaea53cef360482388f248a43fa67b6325782ab1f2e6f7aaaadad05be8352191723a942eb
7
- data.tar.gz: 5d4edb35801ce585c4f03b639f68b56d68b343f9b23ea887f88455f50633ff0e774cd8262cb8896d8d2a85f3f01923cca4549a4cfb0b189221ec08af3e84851e
6
+ metadata.gz: db212abf77c4cf18b4f8f0e8b37cc3ee4d0c291a37d0571375978f08cc6a5fd0a0988d3b9e3fd74c07823d30400fb880e38ae4f27f392e11baafe0b20894080e
7
+ data.tar.gz: f4c8b9de28a9636187a77595f0329dedf5e830a145a9063493c51e294f9636b42be5fe3347d11b39a69d799836a89bc9c6f9d18a47223bc6b687e7c21b3958b0
@@ -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="rbenv: 3.0.2" jdkType="RUBY_SDK" />
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, rbenv: 3.0.2) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="activerecord (v6.1.3, rbenv: 3.0.2) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.3, rbenv: 3.0.2) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.0.2) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.27, rbenv: 3.0.2) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, rbenv: 3.0.2) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, rbenv: 3.0.2) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.11, rbenv: 3.0.2) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, rbenv: 3.0.2) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, rbenv: 3.0.2) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="parser (v3.0.2.0, rbenv: 3.0.2) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, rbenv: 3.0.2) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.0.2) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="rbs (v1.0.4, rbenv: 3.0.2) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.1.1, rbenv: 3.0.2) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.0.2) [gem]" level="application" />
30
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, rbenv: 3.0.2) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, rbenv: 3.0.2) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, rbenv: 3.0.2) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, rbenv: 3.0.2) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.3, rbenv: 3.0.2) [gem]" level="application" />
35
- <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.22.3, rbenv: 3.0.2) [gem]" level="application" />
36
- <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.13.0, rbenv: 3.0.2) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, rbenv: 3.0.2) [gem]" level="application" />
38
- <orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.4.2, rbenv: 3.0.2) [gem]" level="application" />
39
- <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, rbenv: 3.0.2) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, rbenv: 3.0.2) [gem]" level="application" />
41
- <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.1, rbenv: 3.0.2) [gem]" level="application" />
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
@@ -2,4 +2,8 @@
2
2
 
3
3
  ## [0.1.0] - 2021-11-10
4
4
 
5
+ - Change scopes to prevent collisions with models by using `unscoped`.
6
+
7
+ ## [0.1.0] - 2021-11-10
8
+
5
9
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invisible_record (0.1.3)
4
+ invisible_record (0.2.1)
5
5
  activemodel (>= 5)
6
6
  activerecord (>= 5)
7
7
 
@@ -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
- 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
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InvisibleRecord
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.1"
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.3
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-19 00:00:00.000000000 Z
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: