lib/avo/base_resource.rb in avo-3.0.0.pre19 vs lib/avo/base_resource.rb in avo-3.0.1.beta1

- old
+ new

@@ -7,15 +7,14 @@ 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 + def curent_user Avo::Current.user end delegate :params, to: Avo::Current delegate :request, to: Avo::Current delegate :view_context, to: Avo::Current @@ -64,11 +63,10 @@ class_attribute :record_selector, default: true class_attribute :keep_filters_panel_open, default: false class_attribute :extra_params class_attribute :link_to_child_resource, default: false class_attribute :map_view - class_attribute :components, default: {} # EXTRACT: class_attribute :ordering class << self @@ -232,18 +230,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 = Avo::ViewInquirer.new(view) if view.present? + @view = 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,27 +291,23 @@ entity_loader(entity).bag 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] + send("get_#{plural_entity}").find { |entity| entity[:class].to_s == entity_class.to_s }[:arguments] end end def hydrate(record: nil, view: nil, user: nil, params: nil) - @view = Avo::ViewInquirer.new(view) if view.present? + @view = 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 @@ -444,10 +438,10 @@ # We will not overwrite any attributes that come pre-filled in the record. def hydrate_model_with_default_values default_values = get_fields .select do |field| - !field.computed && !field.is_a?(Avo::Fields::HeadingField) + !field.computed end .map do |field| value = field.value if field.type == "belongs_to"