lib/avo/base_resource.rb in avo-3.0.1.beta7 vs lib/avo/base_resource.rb in avo-3.0.1.beta8
- old
+ new
@@ -7,10 +7,11 @@
include Avo::Concerns::CanReplaceItems
include Avo::Concerns::HasControls
include Avo::Concerns::HasStimulusControllers
include Avo::Concerns::ModelClassConstantized
include Avo::Concerns::HasDescription
+ include Avo::Concerns::HasHelpers
# Avo::Current methods
delegate :context, to: Avo::Current
def current_user
Avo::Current.user
@@ -231,18 +232,18 @@
delegate :underscore_name, to: :class
delegate :find_record, to: :class
delegate :model_key, to: :class
def initialize(record: nil, view: nil, user: nil, params: nil)
- @view = view if view.present?
+ @view = Avo::ViewInquirer.new(view) if view.present?
@user = user if user.present?
@params = params if params.present?
if record.present?
@record = record
- hydrate_model_with_default_values if @view == :new
+ hydrate_model_with_default_values if @view&.new?
end
detect_fields
unless self.class.model_class.present?
@@ -293,25 +294,25 @@
end
# def get_action_arguments / def get_filter_arguments / def get_scope_arguments
define_method "get_#{entity}_arguments" do |entity_class|
klass = send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }
-
+
raise "Couldn't find '#{entity_class}' in the 'def #{plural_entity}' method on your '#{self.class}' resource." if klass.nil?
klass[:arguments]
end
end
def hydrate(record: nil, view: nil, user: nil, params: nil)
- @view = view if view.present?
+ @view = Avo::ViewInquirer.new(view) if view.present?
@user = user if user.present?
@params = params if params.present?
if record.present?
@record = record
- hydrate_model_with_default_values if @view == :new
+ hydrate_model_with_default_values if @view&.new?
end
self
end