avo 2.26.0 → 2.26.1.pr1584.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b61c2b5a2648aa08f89b080fe7f8a8c982ef10c51cb361aa24aa53f979dd060
4
- data.tar.gz: 723c552907d3c861383006edea41a9b73da6c609bc87add39f4349569e427b9e
3
+ metadata.gz: 7a5ed608bd7bb2383b9d541e6628cd09ae0f59c074fc01a809c48ad9c8286fb5
4
+ data.tar.gz: 2bea6d2082fb7d5c991ea7a948c3530566752d9d386987b15da6c718339b0ed8
5
5
  SHA512:
6
- metadata.gz: dfbeee5e9548d1c94fee23facf94685393e0cd58fd0079e980ef67707ac52b0545d5aebd7f4e6b3b6b44962d1a3ca540f966c3586660b4582e92484159ac8a3d
7
- data.tar.gz: eebb9b58090526d78af41e3736985788dc69aabe53b0fd9cc02e4b926a7c8debb7daf5b4a9d17e91b357b126500804ef8cf72152d834cfe1b68a04303c1bda88
6
+ metadata.gz: 7216406691593c3219f9a8977ff4c9fdc4520afac0280dd006e28e1b7ad7bf018813434cff06f91f1eaccb96f54e98a29f2932e7e6f892e8e2400d19cfce152e
7
+ data.tar.gz: ff1c08ce8d21d27ad23421298f03fc35cb16f3cfefb21c04fc82a6842c2f2b90083cfb185ae5b40b918c415201bf58dc59f0c5d28af5f61c9f49be54544b5162
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.26.0)
4
+ avo (2.26.1.pr1584.pre.1)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
data/config/master.key ADDED
@@ -0,0 +1 @@
1
+ 2aeb23d82b909d9c6b5abb62f7058c2a
data/lib/avo/app.rb CHANGED
@@ -115,8 +115,45 @@ module Avo
115
115
  end
116
116
  end
117
117
 
118
+ # Fetches the resources available to the application.
119
+ # We have two ways of doing that.
120
+ #
121
+ # 1. Through eager loading.
122
+ # We automatically eager load the resources directory and fetch the descendants from the scanned files.
123
+ # This is the simple way to get started.
124
+ #
125
+ # 2. Manually, declared by the user.
126
+ # We have this option to load the resources because when they are loaded automatically through eager loading,
127
+ # those Resource classes and their methods may trigger loading other classes. And that may disrupt Rails booting process.
128
+ # Ex: AdminResource may use self.model_class = User. That will trigger Ruby to load the User class and itself load
129
+ # other classes in a chain reaction.
130
+ # The scenario that comes up most often is when Rails boots, the routes are being computed which eager loads the resource files.
131
+ # At that boot time some migration might have not been run yet, but Rails tries to access them through model associations,
132
+ # and they are not available.
133
+ #
134
+ # To enable this feature add a `resources` array config in your Avo initializer.
135
+ # config.resources = [
136
+ # "UserResource",
137
+ # "FishResource",
138
+ # ]
139
+ def fetch_resources
140
+ resources = if Avo.configuration.resources.nil?
141
+ BaseResource.descendants
142
+ else
143
+ Avo.configuration.resources
144
+ end
145
+
146
+ resources.map do |resource|
147
+ if resource.is_a?(Class)
148
+ resource
149
+ else
150
+ resource.to_s.safe_constantize
151
+ end
152
+ end
153
+ end
154
+
118
155
  def init_resources
119
- self.resources = BaseResource.descendants
156
+ self.resources = fetch_resources
120
157
  .select do |resource|
121
158
  # Remove the BaseResource. We only need the descendants
122
159
  resource != BaseResource
@@ -41,6 +41,7 @@ module Avo
41
41
  attr_accessor :authorization_client
42
42
  attr_accessor :field_wrapper_layout
43
43
  attr_accessor :sign_out_path_name
44
+ attr_accessor :resources
44
45
  attr_writer :branding
45
46
 
46
47
  def initialize
@@ -92,6 +93,7 @@ module Avo
92
93
  @resource_default_view = :show
93
94
  @authorization_client = :pundit
94
95
  @field_wrapper_layout = :inline
96
+ @resources = nil
95
97
  end
96
98
 
97
99
  def current_user_method(&block)
@@ -3,9 +3,13 @@ module Avo
3
3
  def self.routes
4
4
  Avo::Engine.routes.draw do
5
5
  scope "resources", as: "resources" do
6
- Avo::App.eager_load(:resources) unless Rails.application.config.eager_load
6
+ # Check if the user chose to manually register the resource files.
7
+ # If so, eager_load the resources dir.
8
+ if Avo.configuration.resources.nil?
9
+ Avo::App.eager_load(:resources) unless Rails.application.config.eager_load
10
+ end
7
11
 
8
- BaseResource.descendants
12
+ Avo::App.fetch_resources
9
13
  .select do |resource|
10
14
  resource != :BaseResource
11
15
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.26.0" unless const_defined?(:VERSION)
2
+ VERSION = "2.26.1.pr1584.pre.1" unless const_defined?(:VERSION)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.26.0
4
+ version: 2.26.1.pr1584.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-14 00:00:00.000000000 Z
12
+ date: 2023-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -1695,6 +1695,7 @@ files:
1695
1695
  - config/credentials.yml.enc
1696
1696
  - config/i18n-tasks.yml
1697
1697
  - config/initializers/pagy.rb
1698
+ - config/master.key
1698
1699
  - config/routes.rb
1699
1700
  - config/spring.rb
1700
1701
  - db/factories.rb
@@ -1950,9 +1951,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
1950
1951
  version: 2.6.0
1951
1952
  required_rubygems_version: !ruby/object:Gem::Requirement
1952
1953
  requirements:
1953
- - - ">="
1954
+ - - ">"
1954
1955
  - !ruby/object:Gem::Version
1955
- version: '0'
1956
+ version: 1.3.1
1956
1957
  requirements: []
1957
1958
  rubygems_version: 3.3.3
1958
1959
  signing_key: