effective_resources 2.18.4 → 2.19.0

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: 6afb7b75d0b3a67f0522248e685bb8fb2fa973d6110e4ab5371c6579457eab1b
4
- data.tar.gz: 46b6e23e7fc14d623af21227175aa9c74fc4e5ace265b193e1522e293fa97946
3
+ metadata.gz: 02dcf459be067c9b55f9ab488cbcc9f5fd34c88549c9fc3c58db5f5668496062
4
+ data.tar.gz: c0ba59be147cb88eba96c420685dcafee9e8cc48098ab9a8c878b0cf670eb1db
5
5
  SHA512:
6
- metadata.gz: 2daa3b7acc0596210380e8a6026e92691eb0a1a89591cb5c3aeda0601a740c7790630f2da1213fe31190948071b5319dad46bed18279603e6abbb48dc379153d
7
- data.tar.gz: ad76dbb446443fef1516bcfddbe9d35124157061eb41ed90d4520520b834c29ed670905f74cf4273c75d676707bfc014fd7b267e51fc68c772d501f9246e8ec9
6
+ metadata.gz: bf45b4e61e486e8df1927c6f0b61e2c965ddd1c6c56a2a99386c6813616b81cc541d59193699d422db76f17cbd3dccf2800ec4397e367be2db46e1a7054bd9b7
7
+ data.tar.gz: a980a5d995bc8b7294e01debdd1ca7cfa5d5efc59d3462666677c2d1156f33e33471f188b1add2a6afd7759a965da5fae082bf31f825456caf6582af5fcb2478
@@ -83,7 +83,14 @@ module Effective
83
83
 
84
84
  def resource_scope
85
85
  relation = effective_resource.relation
86
- relation.try(:deep) || relation
86
+
87
+ # Apply jit_preloader if present
88
+ if defined?(JitPreloader) && EffectiveResources.use_jit_preloader
89
+ relation.includes_values = [] # Removes any previously defined .includes()
90
+ relation.jit_preload
91
+ else
92
+ (relation.try(:deep) || relation)
93
+ end
87
94
  end
88
95
 
89
96
  def resource_name # 'thing'
@@ -13,7 +13,7 @@ module Effective
13
13
  end
14
14
 
15
15
  # called by effective_trash and effective_logging
16
- def instance_attributes(only: nil, except: nil)
16
+ def instance_attributes(only: nil, except: nil, associations: true)
17
17
  return {} unless instance.present?
18
18
 
19
19
  # Build up our only and except
@@ -34,43 +34,45 @@ module Effective
34
34
  attributes[association.name] = instance.send(association.name).to_s
35
35
  end
36
36
 
37
- # Grab the instance attributes of each nested resource
38
- nested_resources.each do |association|
39
- next if except.present? && except.include?(association.name)
40
- next unless only.blank? || only.include?(association.name)
37
+ if associations
38
+ # Grab the instance attributes of each nested resource
39
+ nested_resources.each do |association|
40
+ next if except.present? && except.include?(association.name)
41
+ next unless only.blank? || only.include?(association.name)
41
42
 
42
- next if association.options[:through]
43
+ next if association.options[:through]
43
44
 
44
- attributes[association.name] ||= {}
45
+ attributes[association.name] ||= {}
45
46
 
46
- Array(instance.send(association.name)).each_with_index do |child, index|
47
- next unless child.present?
47
+ Array(instance.send(association.name)).each_with_index do |child, index|
48
+ next unless child.present?
48
49
 
49
- resource = Effective::Resource.new(child)
50
- attributes[association.name][index] = resource.instance_attributes(only: only, except: except)
50
+ resource = Effective::Resource.new(child)
51
+ attributes[association.name][index] = resource.instance_attributes(only: only, except: except)
52
+ end
51
53
  end
52
- end
53
54
 
54
- (action_texts + has_ones).each do |association|
55
- next if except.present? && except.include?(association.name)
56
- next unless only.blank? || only.include?(association.name)
55
+ (action_texts + has_ones).each do |association|
56
+ next if except.present? && except.include?(association.name)
57
+ next unless only.blank? || only.include?(association.name)
57
58
 
58
- attributes[association.name] = instance.send(association.name).to_s
59
- end
59
+ attributes[association.name] = instance.send(association.name).to_s
60
+ end
60
61
 
61
- has_manys.each do |association|
62
- next if except.present? && except.include?(association.name)
63
- next unless only.blank? || only.include?(association.name)
62
+ has_manys.each do |association|
63
+ next if except.present? && except.include?(association.name)
64
+ next unless only.blank? || only.include?(association.name)
64
65
 
65
- next if BLACKLIST.include?(association.name)
66
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
67
- end
66
+ next if BLACKLIST.include?(association.name)
67
+ attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
68
+ end
68
69
 
69
- has_and_belongs_to_manys.each do |association|
70
- next if except.present? && except.include?(association.name)
71
- next unless only.blank? || only.include?(association.name)
70
+ has_and_belongs_to_manys.each do |association|
71
+ next if except.present? && except.include?(association.name)
72
+ next unless only.blank? || only.include?(association.name)
72
73
 
73
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
74
+ attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
75
+ end
74
76
  end
75
77
 
76
78
  attributes.delete_if { |_, value| value.blank? }
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.18.4'.freeze
2
+ VERSION = '2.19.0'.freeze
3
3
  end
@@ -7,6 +7,8 @@ require 'effective_resources/effective_gem'
7
7
  module EffectiveResources
8
8
  MAILER_SUBJECT_PROC = Proc.new { |action, subject, resource, opts = {}| subject }
9
9
 
10
+ mattr_accessor :use_jit_preloader
11
+
10
12
  def self.config_keys
11
13
  [
12
14
  :authorization_method, :default_submits,
@@ -18,8 +20,7 @@ module EffectiveResources
18
20
 
19
21
  # We use the newer syntax for serialize calls in rails 7.1 but it changes behaviour
20
22
  def self.serialize_with_coder?
21
- false
22
- #Gem::Version.new(Gem.loaded_specs['rails'].version.to_s) >= Gem::Version.new('7')
23
+ Gem::Version.new(Gem.loaded_specs['rails'].version.to_s) >= Gem::Version.new('7.1')
23
24
  end
24
25
 
25
26
  def self.authorized?(controller, action, resource)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.4
4
+ version: 2.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-29 00:00:00.000000000 Z
11
+ date: 2023-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails