effective_resources 2.16.0 → 2.17.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: 8a70b9647f9b09469826a5a2f553b8c5d61314606068c3b38dc0674f0f856d08
4
- data.tar.gz: 49cf8b3180af7b8884bce5448f152d833298cc5ad2576d2e89ffae91b4ff6853
3
+ metadata.gz: 55ffa99bff7ce09a36f31a7a12f9e0fb3eff53b07110a86724a1b7dad14a0438
4
+ data.tar.gz: 356be85dc5dd7cbaeb0bfdf562b22442ef7102277e4b76bd479e5a0e70823062
5
5
  SHA512:
6
- metadata.gz: 180d32cc45cf6dbebd7054ecac0b1d1f6cdc8648c383f72dcaeb7181845487ac06aa489b4006517369abc009e94b3d0043d23d2e947743f455d3cd553536c533
7
- data.tar.gz: c6077eabe34ab5f6acd89441d4ca2a8688f6075ba3f0fbb6621616b62ea3dfbc1a64f554f7316ddf1713d26df022ab649f9d45c6720299998d14524643e8c21f
6
+ metadata.gz: 676d8e7f03e37d0781c909570b543a8089d9eb5a8e54f215f05bedba1977b9ad49b99e009c2c5cf20a330294c2daf0079c455df957f0198d897b6752210c74a3
7
+ data.tar.gz: eb731aef09e46cea31da8fbdc57c591ec32e09f1c7454678635b51cdee10aedc1e991e3778b215e96da7b5797bc7322151f7864b5509f03ae6dcf8a30fdbdc41
@@ -6,7 +6,11 @@ module EffectiveActsAsEmailFormHelper
6
6
  raise('expected a form') unless form.respond_to?(:object)
7
7
 
8
8
  resource = form.object
9
- raise('expected an acts_as_email_form resource') unless resource.class.respond_to?(:acts_as_email_form?)
9
+
10
+ # Intended for acts_as_email_form but sometimes we use a duck typed object to save these fields as well
11
+ unless resource.class.respond_to?(:acts_as_email_form?) || resource.respond_to?("email_form_action=")
12
+ raise('expected an acts_as_email_form resource or one that responds to email_form_action')
13
+ end
10
14
 
11
15
  # Load the template.
12
16
  email_template = if action.present? && defined?(EffectiveEmailTemplates)
@@ -66,29 +66,41 @@ module Effective
66
66
  end
67
67
  end
68
68
 
69
- def search_form_field_collection(association = nil, max_id = 1000)
69
+ # Load the limit records + 1. If there are all there, return as: :string
70
+ # Otherwise return an Array of the processed results ready for a select field
71
+ # Only hit the database once
72
+ def search_form_field_collection(association = nil, limit: 100)
70
73
  res = (association.nil? ? self : Effective::Resource.new(association))
71
74
 
72
- if res.max_id > max_id
73
- { as: :string }
74
- else
75
- if res.klass.unscoped.respond_to?(:datatables_scope)
76
- { collection: res.klass.datatables_scope.map { |obj| [obj.to_s, obj.id] } }
77
- elsif res.klass.unscoped.respond_to?(:datatables_filter)
78
- collection = res.klass.datatables_filter
75
+ # Return string if this isnt a relational thing
76
+ klass = res.klass
77
+ return { as: :string } unless klass.respond_to?(:unscoped)
79
78
 
80
- if collection.kind_of?(Array)
81
- { collection: collection }
82
- else
83
- { collection: collection.map { |obj| [obj.to_s, obj.id] } }
84
- end
79
+ # Default scope
80
+ scope = res.klass.unscoped
85
81
 
86
- elsif res.klass.unscoped.respond_to?(:sorted)
87
- { collection: res.klass.sorted.map { |obj| [obj.to_s, obj.id] } }
88
- else
89
- { collection: res.klass.all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
90
- end
82
+ scope = if scope.respond_to?(:datatables_scope)
83
+ scope.datatables_scope
84
+ elsif scope.respond_to?(:datatables_filter)
85
+ scope.datatables_filter
86
+ elsif scope.respond_to?(:sorted)
87
+ scope.sorted
88
+ else
89
+ scope
91
90
  end
91
+
92
+ scope = scope.deep if scope.respond_to?(:deep)
93
+ scope = scope.unarchived if scope.respond_to?(:unarchived)
94
+
95
+ # Now that we have the scope figured out let's pull the limit number of records into an Array
96
+ # If there are more than the limit, return as: :string
97
+ resources = scope.limit(limit).to_a
98
+ return { as: :string } unless resources.length < limit
99
+
100
+ # Otherwise there are less than the limit, so we can use a collection select
101
+ {
102
+ collection: resources.map { |obj| [obj.to_s, obj.id] }
103
+ }
92
104
  end
93
105
 
94
106
  end
@@ -22,11 +22,6 @@ module Effective
22
22
  klass.unscoped.table
23
23
  end
24
24
 
25
- def max_id
26
- return 999999 unless klass.respond_to?(:unscoped)
27
- @max_id ||= klass.unscoped.maximum(klass.primary_key).to_i
28
- end
29
-
30
25
  def sql_column(name)
31
26
  column = column(name)
32
27
  return nil unless table && column
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.16.0'.freeze
2
+ VERSION = '2.17.0'.freeze
3
3
  end
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.16.0
4
+ version: 2.17.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-07 00:00:00.000000000 Z
11
+ date: 2023-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails