passive_columns 0.1.3 → 0.2.1

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: 38bc2c892e3bb57a06b9e855c9df40d90a10c65483b87da66030ee5842c7bccc
4
- data.tar.gz: 767c70daaab3f8c5da0e741ad7508321f5017f89eef153684b2b6af3b9c2f480
3
+ metadata.gz: 56f6f5fdf5c333ca2fe7ba55e3974b21b67662362a21848b1b31cf6216e080a1
4
+ data.tar.gz: adbcac3dfba991402e20dc7fc3d2a616498af1998ae4b0d5b4a1a9895254b2c4
5
5
  SHA512:
6
- metadata.gz: 9b9c8d772223ca74da4b648a3450318194418f23ebaa9471f4a686fb05410eac903ce82ec64f193a86c54ea5f34c7770e63f45339710de7d04f9db69119163b9
7
- data.tar.gz: '0489d8d23737e0e3d260c194ed4cbaeca0a37dfb956a63c7c1f889d148a8452291c652528ae5779c15b57e5a956c2d7d52d49d7212d092a6be5379ee1f1f80ef'
6
+ metadata.gz: 9ca11045bc3d47d290e6797c3b834eb4f1d8770ffd955c3be392b51c5d796bd2049c2ae7c849e85f189ce4e91524928cad8a5d55463fc36c082bc54c74c47aa8
7
+ data.tar.gz: df054d53f99a0e292292fe6935ba4dc3e2d707856372043468de0afc121065d9ca515ffb528d7292aba9a5b7f378114ac55b7d8b7e640268ceae897351c18cb1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Passive Columns
2
- A gem that extends `Active Record` to retrieve columns from DB on demand.
3
-
2
+ A gem that extends `Active Record` to retrieve columns from DB on demand.<br>
3
+ Works with `Rails` >= 7 and `Ruby` >= 2.7
4
4
 
5
5
  ## Usage
6
6
 
@@ -5,19 +5,23 @@ module PassiveColumns
5
5
  # to automatically select all columns except passive columns if no columns are selected.
6
6
  module ActiveRecordRelationExtension
7
7
  def exec_main_query(**args)
8
- _set_columns_except_passive_if_nothing_selected
8
+ if klass.try(:_passive_columns).present? && select_values.blank?
9
+ self.select_values = klass.column_names - klass._passive_columns
10
+ end
9
11
  super
10
12
  end
11
13
 
12
14
  def to_sql
13
- _set_columns_except_passive_if_nothing_selected
14
- super
15
- end
15
+ return @to_sql unless @to_sql.nil?
16
16
 
17
- def _set_columns_except_passive_if_nothing_selected
18
- return nil if klass.try(:_passive_columns).blank? || select_values.any?
17
+ # @see ActiveRecord::QueryMethods::assert_mutability!
18
+ return super if @loaded || (defined?(@arel) && @arel)
19
19
 
20
- self.select_values = klass.column_names - klass._passive_columns
20
+ if klass.try(:_passive_columns).present? && select_values.blank?
21
+ self.select_values = klass.column_names - klass._passive_columns
22
+ end
23
+
24
+ super
21
25
  end
22
26
  end
23
27
  end
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # @!attribute [r] lazy_columns
4
- # @return [Array<Symbol>]
5
- # @!attribute [r] model
6
- # @return [LazyColumns]
7
3
  module PassiveColumns
8
4
  # Loader is a class helper that loads a column value from the database if it is not loaded yet.
9
5
  class Loader
@@ -1,17 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require 'passive_columns/active_record_relation_extension'
4
-
5
- # module PassiveColumns # :nodoc:
6
- # class Railtie < Rails::Railtie # :nodoc:
7
- # config.to_prepare do |_app|
8
- # ActiveSupport.on_load(:active_record) do
9
- # ActiveRecord::Relation.prepend(ActiveRecordRelationExtension)
10
- # end
11
- # end
12
- # end
13
- # end
14
-
15
3
  require 'passive_columns/active_record_relation_extension'
16
4
  require 'passive_columns/active_record_association_builder_extension'
17
5
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PassiveColumns
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -85,7 +85,7 @@ module PassiveColumns
85
85
  opts = filter_list.extract_options!
86
86
  if name == :validate && opts[:attributes]&.one?
87
87
  passive_column = opts[:attributes].map(&:to_s) & _passive_columns
88
- opts[:if] = ([-> { attributes.key?(passive_column) }] + Array(opts[:if])) if passive_column.present?
88
+ opts[:if] = ([-> { attributes.key?(passive_column.first) }] + Array(opts[:if])) if passive_column.present?
89
89
  end
90
90
  super(name, *filter_list, opts, &block)
91
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_columns
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
  - Dmitry Golovin