lib/avo/base_resource.rb in avo-2.9.1.pre1 vs lib/avo/base_resource.rb in avo-2.9.1.pre2
- old
+ new
@@ -6,10 +6,11 @@
include ActionView::Helpers::UrlHelper
include Avo::Concerns::HasTools
include Avo::Concerns::HasModel
include Avo::Concerns::HasFields
include Avo::Concerns::HasStimulusControllers
+ include Avo::Concerns::ModelClassConstantized
delegate :view_context, to: ::Avo::App
delegate :simple_format, :content_tag, to: :view_context
delegate :main_app, to: :view_context
delegate :avo, to: :view_context
@@ -27,11 +28,10 @@
class_attribute :title, default: :id
class_attribute :description, default: :id
class_attribute :search_query, default: nil
class_attribute :search_query_help, default: ""
class_attribute :includes, default: []
- class_attribute :model_class
class_attribute :translation_key
class_attribute :default_view_type, default: :table
class_attribute :devise_password_optional, default: false
class_attribute :actions_loader
class_attribute :filters_loader
@@ -76,18 +76,18 @@
query_scope
end
# This resolves the scope when doing "where" queries (not find queries)
def query_scope
- final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: get_model_class) : get_model_class
+ final_scope = resolve_query_scope.present? ? resolve_query_scope.call(model_class: model_class) : model_class
authorization.apply_policy final_scope
end
# This resolves the scope when finding records (not "where" queries)
def find_scope
- final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: get_model_class) : get_model_class
+ final_scope = resolve_find_scope.present? ? resolve_find_scope.call(model_class: model_class) : model_class
authorization.apply_policy final_scope
end
def authorization
@@ -97,18 +97,10 @@
def order_actions
return {} if ordering.blank?
ordering.dig(:actions) || {}
end
-
- def get_model_class
- if model_class.is_a? String
- model_class.safe_constantize
- else
- model_class
- end
- end
end
def initialize
unless self.class.model_class.present?
if model_class.present?
@@ -258,10 +250,10 @@
self.class.name.demodulize.chomp("Resource")
end
def model_class
# get the model class off of the static property
- return self.class.get_model_class if self.class.get_model_class.present?
+ return self.class.model_class if self.class.model_class.present?
# get the model class off of the model
return @model.base_class if @model.present?
# generate a model class