passive_columns 0.3.1 → 0.3.3

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: 3c37d7d720dab3e13b2084d7f6277a35b1d99de88b75eae8ef67b89d67472172
4
- data.tar.gz: 5ada8404f4509e694764d732892c2833d71c94c959c7ae45c080266781473e7e
3
+ metadata.gz: a9a4221690fe58e97942823926abe335c1480f4e2a60886d4020d5616fd65cdb
4
+ data.tar.gz: bee747bdd177f3e7f8471ed3150421ef4dfad35e9458513515daa34c72308bf3
5
5
  SHA512:
6
- metadata.gz: b0ed4cbe6220e1752cb6f98e7b555f31bd178db3941f4a8c2e2d5fb022b3e00eb9abffc71a90cdb29f23fad14cc004e573850d51f9b18b1df3e0e05f4747d32e
7
- data.tar.gz: c73cf064d995e5c9705f609319e4f0609616d346cc17d1a41a8f4efe98cd5cbd934008ca6c0b7a3226d9a9967323038b0bf0fcf9e33f9c5b6ac3d199f86635f2
6
+ metadata.gz: 2c74c6174d74f7075f34eceea98cb0ecf93fa637a4998580e9928b0cc9e3e731f59f1fbbdfff47b5e328ca12cce3143002a31c6ee475f7151f3b4321eff68e27
7
+ data.tar.gz: 4fd85df44dab117a1c032671b7d5b32bb3b4b60f3f73a6006eed17154e2de6b1593d424710e9df68d3855aea2578bacc8d35d80e69bb8bbd8d26164f2447580b
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
 
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'passive_columns/active_record_relation_extension'
4
- require 'passive_columns/active_record_association_builder_extension'
5
4
 
6
5
  module PassiveColumns # :nodoc:
7
6
  class Railtie < Rails::Railtie # :nodoc:
8
7
  config.to_prepare do |_app|
9
8
  ActiveSupport.on_load(:active_record) do
10
9
  ActiveRecord::Relation.prepend ActiveRecordRelationExtension
11
- ActiveRecord::Associations::Builder::Association.prepend ActiveRecordAssociationBuilderExtension
12
10
  end
13
11
  end
14
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PassiveColumns
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.3'
5
5
  end
@@ -94,10 +94,12 @@ module PassiveColumns
94
94
  super(name, *filter_list, opts, &block)
95
95
  end
96
96
 
97
- def cached_find_by_statement(key, &block)
98
- cache = @find_by_statement_cache[connection.prepared_statements]
99
- cache.compute_if_absent(key) do
100
- ActiveRecord::StatementCache.create(connection) do |params|
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|
101
103
  relation = block.call params
102
104
  PassiveColumns.apply_select_scope_to(relation)
103
105
  relation
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.1
4
+ version: 0.3.3
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-11-10 00:00:00.000000000 Z
11
+ date: 2025-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -91,7 +91,6 @@ files:
91
91
  - README.md
92
92
  - Rakefile
93
93
  - lib/passive_columns.rb
94
- - lib/passive_columns/active_record_association_builder_extension.rb
95
94
  - lib/passive_columns/active_record_relation_extension.rb
96
95
  - lib/passive_columns/loader.rb
97
96
  - lib/passive_columns/railtie.rb
@@ -115,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
114
  - !ruby/object:Gem::Version
116
115
  version: '0'
117
116
  requirements: []
118
- rubygems_version: 3.1.6
117
+ rubygems_version: 3.5.11
119
118
  signing_key:
120
119
  specification_version: 4
121
120
  summary: A gem that extends Active Record to retrieve columns from a db on demand
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PassiveColumns
4
- # This module is used to extend the ActiveRecord::Associations::Builder::Association class
5
- # to add a proc with default scope to the association if there is no proc defined.
6
- module ActiveRecordAssociationBuilderExtension
7
- extend ActiveSupport::Concern
8
-
9
- class_methods do
10
- def create_reflection(*)
11
- super.tap do |res|
12
- next if res.polymorphic?
13
- next unless _klass_has_passive_columns(res) && res.scope.nil?
14
-
15
- default_relation = -> { unscoped }
16
- res.instance_variable_set(:@scope, proc { instance_exec(&default_relation) })
17
- end
18
- end
19
-
20
- # Check if the association class has passive columns
21
- # @param [ActiveRecord::Reflection::AssociationReflection] res
22
- def _klass_has_passive_columns(res)
23
- res.klass.respond_to?(:_passive_columns)
24
- rescue NameError
25
- # If +config.eager_load!+ is disabled, an association class may not be loaded yet
26
- # so we can't constantize to check if the class has passive columns.
27
- # In this case, we assume the class has passive columns.
28
- true
29
- end
30
- end
31
- end
32
- end