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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e72f11da44f9f26a2bdb59d3ad4c141a03213c4879283ddb77fa16e0601ada23
4
- data.tar.gz: b13ded4cf1304d6fc467c809cf1bc26a5ea3aa5b54e73214253178d26fbec4aa
3
+ metadata.gz: 348e376c69c70a25be9552144601bb87c486d4c43da5f1d7d0baa9ec1e64b459
4
+ data.tar.gz: 4880ab1e4c89a1525a529da2004b5147fa918241f97a17966871974270ac8368
5
5
  SHA512:
6
- metadata.gz: b9badeaeb8d1ebb13053bc4112735e8d4f749bc87f248c508a437df2ecc42b387590c933bed268231b289458785932efbc1bc4ec75d2e7580431ef85c19a5e37
7
- data.tar.gz: dc93e16661ad86b4191b4a237d51dfd581bf50fe050963b301324282373887048180089424eb8b32eb6b364bf18874ab4a15b30ea3ed8c31efb34c5d739a7764
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.5)
4
+ invisible_record (0.2.0)
5
5
  activemodel (>= 5)
6
6
  activerecord (>= 5)
7
7
 
@@ -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
- @_deleted_timestamp_attr = options[:deleted_timestamp_attribute] || "deleted_at"
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: @_deleted_timestamp_attr
25
+ Helper.define_hidden_attributes self, deleted_ts_attr: deleted_timestamp_attr
25
26
 
26
- Helper.define_actions self, deleted_ts_attr: @_deleted_timestamp_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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InvisibleRecord
4
- VERSION = "0.1.5"
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.5
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-23 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: