effective_resources 1.9.6 → 1.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e5b54802ada357459497c873ed7958745da7a62def14f6e0cea1b8b09b1ad3a
4
- data.tar.gz: 391b11cbab23ea721aa01bb1ada824ab064b1182f16bc88083591746205424f2
3
+ metadata.gz: 36829df631b235ec0cb1a9cc26616fd15c100bfcb2314f57edd1a70f5eda3f86
4
+ data.tar.gz: 3b93094b4d501b4d737f0011b337d806eb67305642b4bb4f2e6263672c5b9267
5
5
  SHA512:
6
- metadata.gz: e33a16caedeaf449a75457ff5ee8ed7af961b3092e871ea3a404739054cb8fbf7fe0b9f388312e100ec6896c5f597591402a2efd0845a79bd4e44c1aa99fb16c
7
- data.tar.gz: eb12d90c64e6e8467fd3dbc6733f7e7da0ee02a94231f33f464dc1896056e01f4b1a3e8998aa949815d741bb760fd732697c63682fe303cef2a132833ff801ee
6
+ metadata.gz: 032ca3f256846e3b666bc33f5452fb7aefefd910abc9b4c1d9f068ec04b82e6b5c61999e0107a4feb03509921b0f333ce43b9a155c2fcb04eebe7a4d955544db
7
+ data.tar.gz: 2d1c59030ea9e8ec2d78efe2d5c9b15571abc0ec9f86fbc506250af2703b8ad87388e2ebc3f517c1d47101b31fcbacada059ca94bfdc51fb7d24b363121af5ad
@@ -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
@@ -125,16 +125,16 @@ module ActsAsStatused
125
125
  define_method("#{sym}?") { status == sym.to_s }
126
126
  define_method("was_#{sym}?") { send("#{sym}_at").present? }
127
127
 
128
- unless has_attribute?("#{sym}_at")
128
+ #unless has_attribute?("#{sym}_at")
129
129
  define_method("#{sym}_at") { status_steps["#{sym}_at".to_sym] }
130
130
  define_method("#{sym}_at=") { |value| status_steps["#{sym}_at".to_sym] = value }
131
- end
131
+ #end
132
132
 
133
- unless has_attribute?("#{sym}_by_id")
133
+ #unless has_attribute?("#{sym}_by_id")
134
134
  define_method("#{sym}_by") { acts_as_statused_by_user(sym) }
135
135
  define_method("#{sym}_by_id") { status_steps["#{sym}_by".to_sym] }
136
136
  define_method("#{sym}_by_id=") { |value| status_steps["#{sym}_by".to_sym] = value }
137
- end
137
+ #end
138
138
 
139
139
  # approved!
140
140
  define_method("#{sym}!") do |atts = {}|
@@ -180,4 +180,3 @@ module ActsAsStatused
180
180
  end
181
181
 
182
182
  end
183
-
@@ -12,11 +12,11 @@ module Effective
12
12
  @controller_path ||= route_name #[namespace, plural_name].compact * '/')
13
13
  end
14
14
 
15
- def engines
16
- return ([Rails.application] + Rails::Engine.subclasses.reverse) unless tenant?
17
-
18
- [Rails.application, Tenant.Engine] + Rails::Engine.subclasses.reverse.reject do |klass|
19
- tenant_engines_blacklist.any? { |name| klass.name.start_with?(name) }
15
+ def route_engines
16
+ if tenant? && Tenant.current.present?
17
+ [Rails.application, Tenant.Engine] + (Rails::Engine.subclasses.reverse - Tenant.route_engines)
18
+ else
19
+ [Rails.application] + Rails::Engine.subclasses.reverse
20
20
  end
21
21
  end
22
22
 
@@ -24,6 +24,8 @@ module Effective
24
24
  @routes ||= begin
25
25
  routes = nil
26
26
 
27
+ engines = route_engines()
28
+
27
29
  # Check from controller_path. This is generally correct.
28
30
  engines.each do |engine|
29
31
  routes = engine.routes.routes.select do |route|
@@ -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.6'.freeze
2
+ VERSION = '1.9.10'.freeze
3
3
  end
@@ -62,6 +62,21 @@ module EffectiveResources
62
62
  connection.transaction { yield }
63
63
  end
64
64
 
65
+ # Used by streaming CSV export in datatables
66
+ def self.with_resource_enumerator(&block)
67
+ raise('expected a block') unless block_given?
68
+
69
+ tenant = Tenant.current if defined?(Tenant)
70
+
71
+ if tenant
72
+ Enumerator.new do |enumerator|
73
+ Tenant.as(tenant) { yield(enumerator) }
74
+ end
75
+ else
76
+ Enumerator.new { |enumerator| yield(enumerator) }
77
+ end
78
+ end
79
+
65
80
  def self.truthy?(value)
66
81
  if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
67
82
  ::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.6
4
+ version: 1.9.10
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-11-28 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails