avo 2.9.1.pre1 → 2.9.1.pre2

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: 1b6ce5aac2f8a3f263f31ec99550e1d09d98dec31fac4852affb0f387ec3eb45
4
- data.tar.gz: e8b7d4c9db66b852abec3593830e7053f2e472459548f9c6a60e3eca1838517a
3
+ metadata.gz: 9401cff40f8b21f28409534ff2540ef6deb94620952b75ede2df8c2a38dfd81f
4
+ data.tar.gz: 20c4c6e211d46e6818879d26e82619d96eb8639804c84fe35e1a94c168655e5f
5
5
  SHA512:
6
- metadata.gz: 18a93629ab488cf5c9b80eb21fb80c4e1289a031417937de0fd8434e73f206ebc1cd6254dd1fde9f423894b76ebdc04390d03088c4b2a685d9371f54440fd3ff
7
- data.tar.gz: 9e1073af2957a468ea098e42d726fc49c96ec7a1b5866d6585f7ed318cab674a6e2dc4f80170c409e5153764eb44fc9f676c79658b9d26d3062f63ac5b7e264e
6
+ metadata.gz: b053e8998efda171728723c33b725098962df7b64a4b62d2d59c4f6f094039e96bb9eb38d848a076d3cf4df8faa6dbe6f97d2e9de58f81b8601158441178c0dc
7
+ data.tar.gz: 9d65eb151f122ddd4b34fbc775e9dc9765efc30364c49d6ba2b079f4435d8d062b2181b927dc8d7f22cb84a1d808d31f9b4c49ced3c612b566a363e1e45b6b1c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.9.1.pre1)
4
+ avo (2.9.1.pre2)
5
5
  active_link_to
6
6
  addressable
7
7
  breadcrumbs_on_rails
@@ -8,6 +8,7 @@ module Avo
8
8
  include Avo::Concerns::HasModel
9
9
  include Avo::Concerns::HasFields
10
10
  include Avo::Concerns::HasStimulusControllers
11
+ include Avo::Concerns::ModelClassConstantized
11
12
 
12
13
  delegate :view_context, to: ::Avo::App
13
14
  delegate :simple_format, :content_tag, to: :view_context
@@ -29,7 +30,6 @@ module Avo
29
30
  class_attribute :search_query, default: nil
30
31
  class_attribute :search_query_help, default: ""
31
32
  class_attribute :includes, default: []
32
- class_attribute :model_class
33
33
  class_attribute :translation_key
34
34
  class_attribute :default_view_type, default: :table
35
35
  class_attribute :devise_password_optional, default: false
@@ -78,14 +78,14 @@ module Avo
78
78
 
79
79
  # This resolves the scope when doing "where" queries (not find queries)
80
80
  def query_scope
81
- final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: get_model_class) : get_model_class
81
+ final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: model_class) : model_class
82
82
 
83
83
  authorization.apply_policy final_scope
84
84
  end
85
85
 
86
86
  # This resolves the scope when finding records (not "where" queries)
87
87
  def find_scope
88
- final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: get_model_class) : get_model_class
88
+ final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: model_class) : model_class
89
89
 
90
90
  authorization.apply_policy final_scope
91
91
  end
@@ -99,14 +99,6 @@ module Avo
99
99
 
100
100
  ordering.dig(:actions) || {}
101
101
  end
102
-
103
- def get_model_class
104
- if model_class.is_a? String
105
- model_class.safe_constantize
106
- else
107
- model_class
108
- end
109
- end
110
102
  end
111
103
 
112
104
  def initialize
@@ -260,7 +252,7 @@ module Avo
260
252
 
261
253
  def model_class
262
254
  # get the model class off of the static property
263
- return self.class.get_model_class if self.class.get_model_class.present?
255
+ return self.class.model_class if self.class.model_class.present?
264
256
 
265
257
  # get the model class off of the model
266
258
  return @model.base_class if @model.present?
@@ -0,0 +1,23 @@
1
+ module Avo
2
+ module Concerns
3
+ module ModelClassConstantized
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ attr_reader :model_class
8
+
9
+ # Cast the model class to a constantized version and memoize it like that
10
+ def model_class=(value)
11
+ @model_class = case value
12
+ when Class
13
+ value
14
+ when String, Symbol
15
+ value.to_s.safe_constantize
16
+ else
17
+ raise ArgumentError.new "Failed to find a proper model class for #{self.to_s}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "2.9.1.pre1" unless const_defined?(:VERSION)
2
+ VERSION = "2.9.1.pre2" 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.9.1.pre1
4
+ version: 2.9.1.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Marin
@@ -1179,6 +1179,7 @@ files:
1179
1179
  - lib/avo/concerns/has_model.rb
1180
1180
  - lib/avo/concerns/has_stimulus_controllers.rb
1181
1181
  - lib/avo/concerns/has_tools.rb
1182
+ - lib/avo/concerns/model_class_constantized.rb
1182
1183
  - lib/avo/configuration.rb
1183
1184
  - lib/avo/dashboards/base_dashboard.rb
1184
1185
  - lib/avo/dashboards/base_divider.rb