avo 2.26.2.pre.pr1579 → 2.26.3.pre.pr1601

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: ff9b60d0d2f1fc8e8f3536899e3559d78886342441ab558991dc2b374fbc45ac
4
- data.tar.gz: 3bab366736547f5d041c5e1283b76b569d8ae788d25eafc4bf919ffb17d3a3e8
3
+ metadata.gz: 4bb91ab45ce78d6311390251a678a7d015f38834e702999e5073b8d537bf4342
4
+ data.tar.gz: 5ba8c4a46f6c6bdaebb1ce8a35790f7acb14c9b05e05b12cd60bf58521a7a991
5
5
  SHA512:
6
- metadata.gz: b159c53be13567f56c149d7cf5d7c16af84dcf1f55f69662d09317c54b5151b628798fc26cf02175a6dd9b19b734e7a4fc3918cbf4b860aff50f53f82d1b9f46
7
- data.tar.gz: e74aa9525374ede47f68c0ca70b0ecf4824ddaae4bb2430538462c4226d53a431f35dbfd54ed6dfbd8dad528e21174ada30f9dec34459a5480ad3dd0ebb71a23
6
+ metadata.gz: 9a9082834cd4f9b0de2382f60799c927901bead7775683438a714a6c05815f7f5bec1d758aab4f6cc76af15fbf9f1642f0161ee8183911973dfc931718a21122
7
+ data.tar.gz: 6e7754cb9fe3b4c723e1412b3804035a8b62c1e64bf568e5729ba17d68b989b76b33422918c4b09c3966e6107d616280439f7d0e48798f09b3a3ddaa8e10dac7
data/Gemfile CHANGED
@@ -80,8 +80,9 @@ group :development do
80
80
  gem "brakeman"
81
81
  end
82
82
 
83
+ gem "awesome_print"
84
+
83
85
  group :development, :test do
84
- gem "awesome_print"
85
86
  gem "faker", require: false
86
87
  gem "i18n-tasks", "~> 1.0.12"
87
88
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.26.2.pre.pr1579)
4
+ avo (2.26.3.pre.pr1601)
5
5
  actionview (>= 6.0)
6
6
  active_link_to
7
7
  activerecord (>= 6.0)
data/bin/prod ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ PORT="${PORT:-3030}"
4
+ export PORT
5
+
6
+ if command -v overmind &> /dev/null; then
7
+ overmind start -f Procfile "$@"
8
+ else
9
+ foreman start -f Procfile "$@"
10
+ fi
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
@@ -264,6 +264,10 @@ module Avo
264
264
  panelfull_items = []
265
265
 
266
266
  items.each do |item|
267
+ if item.respond_to? :hydrate
268
+ item.hydrate(view: view)
269
+ end
270
+
267
271
  # fields and tabs can be hidden on some views
268
272
  if item.respond_to? :visible_on?
269
273
  next unless item.visible_on?(view)
@@ -13,6 +13,13 @@ module Avo
13
13
 
14
14
  def visible_items
15
15
  items
16
+ .map do |item|
17
+ if item.respond_to? :hydrate
18
+ item.hydrate(view: view)
19
+ end
20
+
21
+ item
22
+ end
16
23
  .map do |item|
17
24
  visible(item) ? item : nil
18
25
  end
@@ -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.2.pre.pr1579" unless const_defined?(:VERSION)
2
+ VERSION = "2.26.3.pre.pr1601" 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.2.pre.pr1579
4
+ version: 2.26.3.pre.pr1601
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-26 00:00:00.000000000 Z
12
+ date: 2023-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -1686,6 +1686,7 @@ files:
1686
1686
  - bin/dev
1687
1687
  - bin/helpers.rb
1688
1688
  - bin/init
1689
+ - bin/prod
1689
1690
  - bin/rails
1690
1691
  - bin/rspec
1691
1692
  - bin/spring