effective_resources 1.9.8 → 1.9.12

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: bc155a948b5a244e8a5c7beaa9d634eb1aab656cde915aecaeba3a3e69fa8d69
4
- data.tar.gz: 947a11397a9b568cbd29c586fd79e310c4f512bfcf4aed7a8048be567afbadae
3
+ metadata.gz: c84fc7b85367038b6acea82974e25be087fe2f1f5dc02acb26a642f2e30a4456
4
+ data.tar.gz: 18a47801a18fd254bb1d9d4b51ec7b0582194ecfd53442108d02c5b52b6dd560
5
5
  SHA512:
6
- metadata.gz: dbf358c58522cb4153495a960f5f3b46da781d0489149b87cdf4498441582b990c0399982ae3d897277d97433c03d9b1de490c3e4607af1c8ee1f935ca2efdf9
7
- data.tar.gz: 4ab89fad47f59f7e18ad2ef674589e41a8fb47c4fc6f21133ce0aeccf3b892bb6c5b5832e93c1019ca8682c329b61396f5e69be8e991a6ff31fad69d53dad192
6
+ metadata.gz: 821be02e8c9302b4459facfddf6c64423040fd21da5627c6b32ef4ee72ea8e739df1fa4dc60037c9cf97cbf6b0eb83d4c7d6bf71268a4b0ac21513f9e8829f8e
7
+ data.tar.gz: 23917cb4747779edf1cd13014f1a181baebb0114c6035869dd72ee7eda95df0ec8a96ffbbb04c08c0ed631c92957d6a43418c5b9aaa7d76cc68ad86b42e5cae8
@@ -1,11 +1,9 @@
1
- # frozen_sting_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module EffectiveResourcesPrivateHelper
4
4
  REPLACE_PAGE_ACTIONS = {'update' => :edit, 'create' => :new}
5
5
  BLACKLIST = [:default, :only, :except, :if, :unless, :redirect, :success, :danger, :klass]
6
6
 
7
- DATA_CONFIRM = 'data-confirm'
8
-
9
7
  def permitted_resource_actions(resource, actions)
10
8
  page_action = REPLACE_PAGE_ACTIONS[params[:action]] || params[:action].try(:to_sym) || :save
11
9
  executor = Effective::ResourceExec.new(self, resource)
@@ -38,8 +36,8 @@ module EffectiveResourcesPrivateHelper
38
36
  end
39
37
 
40
38
  # Replace resource name in any token strings
41
- if opts[DATA_CONFIRM].present? && opts[DATA_CONFIRM].include?('@resource'.freeze)
42
- opts[DATA_CONFIRM] = opts[DATA_CONFIRM].gsub('@resource'.freeze, resource_to_s)
39
+ if opts['data-confirm'].present? && opts['data-confirm'].include?('@resource'.freeze)
40
+ opts['data-confirm'] = opts['data-confirm'].gsub('@resource'.freeze, resource_to_s)
43
41
  end
44
42
 
45
43
  # Assign class
@@ -160,9 +160,7 @@ module EffectiveDeviseUser
160
160
  args.last[:tenant] ||= tenant
161
161
  end
162
162
 
163
- wait = (5 if notification == :invitation_instructions && !Rails.env.test?)
164
-
165
- devise_mailer.send(notification, self, *args).deliver_later(wait: wait)
163
+ devise_mailer.send(notification, self, *args).deliver_now
166
164
  end
167
165
 
168
166
  end
@@ -14,9 +14,7 @@ module Effective
14
14
 
15
15
  def route_engines
16
16
  if tenant? && Tenant.current.present?
17
- [Rails.application, Tenant.Engine] + Rails::Engine.subclasses.reverse.reject do |klass|
18
- tenant_engines_blacklist.any? { |name| klass.name.start_with?(name) }
19
- end
17
+ [Rails.application, Tenant.Engine] + (Rails::Engine.subclasses.reverse - Tenant.route_engines)
20
18
  else
21
19
  [Rails.application] + Rails::Engine.subclasses.reverse
22
20
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Associations
4
-
5
6
  def macros
6
7
  [:belongs_to, :belongs_to_polymorphic, :has_many, :has_and_belongs_to_many, :has_one]
7
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Attributes
@@ -1,4 +1,4 @@
1
- # frozen_sting_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Effective
4
4
  module Resources
@@ -1,4 +1,4 @@
1
- # frozen_sting_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Effective
4
4
  module Resources
@@ -1,4 +1,4 @@
1
- # frozen_sting_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Effective
4
4
  module Resources
@@ -1,4 +1,4 @@
1
- # frozen_sting_literals: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Effective
4
4
  module Resources
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Instance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Klass
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Model
@@ -18,7 +20,3 @@ module Effective
18
20
  end
19
21
  end
20
22
  end
21
-
22
-
23
-
24
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Naming
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Relation
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Sql
4
-
5
6
  def column(name)
6
7
  name = name.to_s
7
- columns.find { |col| col.name == name || (belongs_to(name) && col.name == belongs_to(name).foreign_key) }
8
+ bt = belongs_to(name)
9
+
10
+ columns.find { |col| col.name == name || (bt && col.name == bt.foreign_key) }
8
11
  end
9
12
 
10
13
  def columns
@@ -32,17 +35,18 @@ module Effective
32
35
  end
33
36
 
34
37
  def sql_direction(name)
35
- name.to_s.downcase == 'desc' ? 'DESC'.freeze : 'ASC'.freeze
38
+ name.to_s.downcase == 'desc' ? 'DESC' : 'ASC'
36
39
  end
37
40
 
38
41
  # This is for EffectiveDatatables (col as:)
39
42
  # Might be :name, or 'users.name'
40
43
  def sql_type(name)
41
- name = name.to_s.split('.').first
44
+ name = (name.kind_of?(String) ? name.split('.').first : name.to_s)
42
45
 
43
46
  return :belongs_to if belongs_to(name)
44
47
 
45
- column = column(name)
48
+ # Skip using columns() cause we dont need to check for belongs_to
49
+ column = columns.find { |col| col.name == name }
46
50
 
47
51
  if column.present?
48
52
  column.type
@@ -105,13 +109,11 @@ module Effective
105
109
  end
106
110
 
107
111
  def postgres?
108
- return @postgres unless @postgres.nil?
109
- @postgres ||= (klass.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) rescue false)
112
+ klass.connection.adapter_name == 'PostgreSQL'
110
113
  end
111
114
 
112
115
  def mysql?
113
- return @mysql unless @mysql.nil?
114
- @mysql ||= (klass.connection.kind_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) rescue false)
116
+ klass.connection.adapter_name == 'MySQL'
115
117
  end
116
118
 
117
119
  def is_null(sql_column)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module Resources
3
5
  module Tenants
@@ -15,10 +17,6 @@ module Effective
15
17
  name if Rails.application.config.tenants[name].present?
16
18
  end
17
19
 
18
- def tenant_engines_blacklist
19
- return [] unless tenant?
20
- Rails.application.config.tenants.map { |name, _| name.to_s.classify }
21
- end
22
20
  end
23
21
  end
24
22
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.9.8'.freeze
2
+ VERSION = '1.9.12'.freeze
3
3
  end
@@ -52,16 +52,27 @@ module EffectiveResources
52
52
  end
53
53
 
54
54
  def self.transaction(resource = nil, &block)
55
- connection = (resource if resource.respond_to?(:transaction))
56
- connection ||= (resource.class if resource.class.respond_to?(:transaction))
57
- connection ||= '::ApplicationRecord'.safe_constantize
58
- connection ||= 'ActiveRecord::Base'.safe_constantize
59
-
55
+ connection = 'ActiveRecord::Base'.safe_constantize
60
56
  raise('unable to determine transaction class') unless connection.present?
61
57
 
62
58
  connection.transaction { yield }
63
59
  end
64
60
 
61
+ # Used by streaming CSV export in datatables
62
+ def self.with_resource_enumerator(&block)
63
+ raise('expected a block') unless block_given?
64
+
65
+ tenant = Tenant.current if defined?(Tenant)
66
+
67
+ if tenant
68
+ Enumerator.new do |enumerator|
69
+ Tenant.as(tenant) { yield(enumerator) }
70
+ end
71
+ else
72
+ Enumerator.new { |enumerator| yield(enumerator) }
73
+ end
74
+ end
75
+
65
76
  def self.truthy?(value)
66
77
  if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
67
78
  ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
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: 1.9.8
4
+ version: 1.9.12
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: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails