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 +4 -4
- data/README.md +2 -2
- data/lib/passive_columns/active_record_relation_extension.rb +11 -7
- data/lib/passive_columns/loader.rb +0 -4
- data/lib/passive_columns/railtie.rb +0 -12
- data/lib/passive_columns/version.rb +1 -1
- data/lib/passive_columns.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56f6f5fdf5c333ca2fe7ba55e3974b21b67662362a21848b1b31cf6216e080a1
|
|
4
|
+
data.tar.gz: adbcac3dfba991402e20dc7fc3d2a616498af1998ae4b0d5b4a1a9895254b2c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9ca11045bc3d47d290e6797c3b834eb4f1d8770ffd955c3be392b51c5d796bd2049c2ae7c849e85f189ce4e91524928cad8a5d55463fc36c082bc54c74c47aa8
|
|
7
|
+
data.tar.gz: df054d53f99a0e292292fe6935ba4dc3e2d707856372043468de0afc121065d9ca515ffb528d7292aba9a5b7f378114ac55b7d8b7e640268ceae897351c18cb1
|
data/README.md
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
14
|
-
super
|
|
15
|
-
end
|
|
15
|
+
return @to_sql unless @to_sql.nil?
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
return
|
|
17
|
+
# @see ActiveRecord::QueryMethods::assert_mutability!
|
|
18
|
+
return super if @loaded || (defined?(@arel) && @arel)
|
|
19
19
|
|
|
20
|
-
|
|
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
|
|
data/lib/passive_columns.rb
CHANGED
|
@@ -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
|