avo 0.5.0.beta6 → 0.5.0.beta7

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: feb0f2107251ad2cef1a10c6980d4ffecde53332b8c584697ebcefb2f341edb5
4
- data.tar.gz: 49d8bedcfd86bfdb44e8426c393e485451020ca5825528948a199af78f722995
3
+ metadata.gz: 48ae6c7207084645f7a7a14a462ebc7161f94801e100054d53f48722f758f9c2
4
+ data.tar.gz: dcc5caabc807328ddd1c52c640d446d88d84c58f786b693d59455f1e7d251744
5
5
  SHA512:
6
- metadata.gz: c5fc2c13d27849cc5c7b5456b9bbb1dea9798f8209746e38cc1d26cbd8f7cd158beab29c8407be0eca1cd0feedc4bfb03a8290941b9a5e66d55dc300cffada06
7
- data.tar.gz: cd2c38578315087e25b5584de1145bba9bb0454c301f8587ad620f1799158dcddab644e6a8d73677a463b8d344f082cba93aaf53fd2e5a5d1cc9a0a2b0573ff4
6
+ metadata.gz: '038536c5cc11eeae399c9cbb59d366868bb3affe39592075c8852d65df49f1a362917a9e96861c804e807a6ed0e2cb39932e5bb82cb04d54b9830301a44b7056'
7
+ data.tar.gz: b9d16aa4a175c5a43a0ec24059e4715febc755cea5b28be601b0b9fb22f9414881ec170b6ad9e1dbe2e51a77d6b8d5cae7e620d8d1d7dc95c4c01c988f9f09ca
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (0.5.0.beta6)
4
+ avo (0.5.0.beta7)
5
5
  active_link_to
6
6
  countries
7
7
  hotwire-rails
@@ -155,7 +155,12 @@ module Avo
155
155
  # Gets the Avo resource for this request based on the request from the `resource_name` "param"
156
156
  # Ex: Avo::Resources::Project, Avo::Resources::Team, Avo::Resources::User
157
157
  def resource
158
- App.get_resource @resource_name.to_s.camelize.singularize
158
+
159
+ resource = App.get_resource @resource_name.to_s.camelize.singularize
160
+
161
+ return resource if resource.present?
162
+
163
+ App.get_resource_by_controller_name @resource_name
159
164
  end
160
165
 
161
166
  def related_resource
data/lib/avo/app.rb CHANGED
@@ -122,7 +122,7 @@ module Avo
122
122
 
123
123
  # Returns the Avo resource by camelized name
124
124
  #
125
- # get_resource_by_name('User') => Avo::Resources::User
125
+ # get_resource_by_name('User') => UserResource
126
126
  def get_resource(resource)
127
127
  self.app[:resources].find do |available_resource|
128
128
  "#{resource}Resource".safe_constantize == available_resource.class
@@ -131,21 +131,31 @@ module Avo
131
131
 
132
132
  # Returns the Avo resource by singular snake_cased name
133
133
  #
134
- # get_resource_by_name('user') => Avo::Resources::User
134
+ # get_resource_by_name('user') => UserResource
135
135
  def get_resource_by_name(name)
136
136
  self.get_resource name.singularize.camelize
137
137
  end
138
138
 
139
139
  # Returns the Avo resource by singular snake_cased name
140
140
  #
141
- # get_resource_by_name('User') => Avo::Resources::User
142
- # get_resource_by_name(User) => Avo::Resources::User
141
+ # get_resource_by_name('User') => UserResource
142
+ # get_resource_by_name(User) => UserResource
143
143
  def get_resource_by_model_name(name)
144
144
  get_resources.find do |resource|
145
145
  resource.model_class.model_name.name == name.to_s
146
146
  end
147
147
  end
148
148
 
149
+ # Returns the Avo resource by singular snake_cased name
150
+ #
151
+ # get_resource_by_controller_name('delayed_backend_active_record_jobs') => DelayedJobResource
152
+ # get_resource_by_controller_name('users') => UserResource
153
+ def get_resource_by_controller_name(name)
154
+ get_resources.find do |resource|
155
+ resource.model_class.to_s.pluralize.underscore.gsub('/', '_') == name.to_s
156
+ end
157
+ end
158
+
149
159
  # Returns the Rails model class by singular snake_cased name
150
160
  #
151
161
  # get_model_class_by_name('user') => User
@@ -174,11 +184,15 @@ module Avo
174
184
  Proc.new do
175
185
  BaseResource.descendants
176
186
  .select do |resource|
177
- resource != :Resource
187
+ resource != :BaseResource
178
188
  end
179
189
  .map do |resource|
180
190
  if resource.is_a? Class
181
- route_key = resource.to_s.underscore.gsub('_resource', '').downcase.pluralize.to_sym
191
+ if resource.model_class.present?
192
+ route_key = resource.model_class.model_name.route_key
193
+ else
194
+ route_key = resource.to_s.underscore.gsub('_resource', '').downcase.pluralize.to_sym
195
+ end
182
196
 
183
197
  resources route_key
184
198
  end
@@ -11,6 +11,7 @@ module Avo
11
11
  class_attribute :title, default: :id
12
12
  class_attribute :search, default: [:id]
13
13
  class_attribute :includes, default: []
14
+ class_attribute :model_class
14
15
  class_attribute :translation_key
15
16
  class_attribute :default_view_type, default: :table
16
17
  class_attribute :devise_password_optional, default: false
@@ -158,6 +159,8 @@ module Avo
158
159
  end
159
160
 
160
161
  def model_class
162
+ return self.class.model_class if self.class.model_class.present?
163
+
161
164
  return @model.class if @model.present?
162
165
 
163
166
  self.class.name.demodulize.chomp('Resource').safe_constantize
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = '0.5.0.beta6'
2
+ VERSION = '0.5.0.beta7'
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: 0.5.0.beta6
4
+ version: 0.5.0.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin