passive_columns 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baf809905aa69dc2f9ee36bcb51c2c2187790c2d2455fdb0ba828546c260625f
4
- data.tar.gz: 005e105b072004ef89f410d4470a760be689b589a9f767c6a907e31e7ffd9644
3
+ metadata.gz: 0d9695006ebeabd65f0e14a0677f0161b90a13c2efc08718275a0f3c689f2d05
4
+ data.tar.gz: 78f853029324f5c67d042ba402ba469afc0b295f227a8dbc070eecdffcbfa8de
5
5
  SHA512:
6
- metadata.gz: 02f54e4528a456f37d07e6340bbc0aeb01c672db28002ad681d5394c8d4617f3bf50ae97b1eaaa13c1d4561712554e95d5612ec239fe0bf2f246db2316f2cf6c
7
- data.tar.gz: 72b5738f265fdc05deb98defee7853fc37427ed8922e19f0e1911bffd9cbe20e48a5a62b49afc188096e6cb9a01c958b1b851f7a1fca709d2332ea10ad4c585f
6
+ metadata.gz: 70793175ba5c45e30ac3807329948c75ddb8c48c3d22c861abbbc4dba5229165b58a0c77d899bd88ae1beba811768c485e91bc79ffdcaabdcad4276024e50d82
7
+ data.tar.gz: f1a0c0521c4c446453bbf5d675c16e12835a0db2d53276fe8515da9b5d143ee66415364d401536c35733ffb0c3c0023289f4df15f311a28765ac5272cfaf44bd
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Passive Columns
2
2
  A gem that extends `Active Record` to retrieve columns from DB on demand.<br>
3
- Works with `Rails` >= 7 and `Ruby` >= 2.7
3
+ Works with `Rails` >= 6.1 and `Ruby` >= 2.7
4
4
 
5
5
  ## Usage
6
6
 
@@ -6,16 +6,12 @@ module PassiveColumns
6
6
  module ActiveRecordRelationExtension
7
7
  if ActiveRecord::VERSION::MAJOR >= 7
8
8
  def exec_main_query(...)
9
- if klass.try(:_passive_columns).present? && select_values.blank?
10
- self.select_values = klass.column_names - klass._passive_columns
11
- end
9
+ PassiveColumns.apply_select_scope_to(self)
12
10
  super
13
11
  end
14
12
  else
15
13
  def exec_queries(...)
16
- if klass.try(:_passive_columns).present? && select_values.blank?
17
- self.select_values = klass.column_names - klass._passive_columns
18
- end
14
+ PassiveColumns.apply_select_scope_to(self)
19
15
  super
20
16
  end
21
17
  end
@@ -26,10 +22,7 @@ module PassiveColumns
26
22
  # @see ActiveRecord::QueryMethods::assert_mutability!
27
23
  return super if @loaded || (defined?(@arel) && @arel)
28
24
 
29
- if klass.try(:_passive_columns).present? && select_values.blank?
30
- self.select_values = klass.column_names - klass._passive_columns
31
- end
32
-
25
+ PassiveColumns.apply_select_scope_to(self)
33
26
  super
34
27
  end
35
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PassiveColumns
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -93,6 +93,30 @@ module PassiveColumns
93
93
  end
94
94
  super(name, *filter_list, opts, &block)
95
95
  end
96
+
97
+ def cached_find_by_statement(*args, &block)
98
+ con = args.size == 2 ? args[0] : connection
99
+ cache = @find_by_statement_cache[con.prepared_statements]
100
+
101
+ cache.compute_if_absent(args.last) do
102
+ ActiveRecord::StatementCache.create(con) do |params|
103
+ relation = block.call params
104
+ PassiveColumns.apply_select_scope_to(relation)
105
+ relation
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ # This method is used to apply the select scope to the relation.
112
+ # It is used to automatically select all columns except passive columns if no columns are selected.
113
+ # @param [ActiveRecord::Relation] relation
114
+ # @return [void]
115
+ def self.apply_select_scope_to(relation)
116
+ return if relation.klass.try(:_passive_columns).blank?
117
+ return if relation.select_values.present?
118
+
119
+ relation.select_values = relation.klass.column_names - relation.klass._passive_columns
96
120
  end
97
121
 
98
122
  # This method loads a column value, if not already loaded, from the database
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_columns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Golovin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-16 00:00:00.000000000 Z
11
+ date: 2024-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.3.26
118
+ rubygems_version: 3.5.11
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: A gem that extends Active Record to retrieve columns from a db on demand