Sha256: 385f3a5c2d0985138f05edcb1dcdafcdca30c1b65fc1373b57c29689234d2da5

Contents?: true

Size: 1.85 KB

Versions: 38

Compression:

Stored size: 1.85 KB

Contents

require "action_controller"

module EasyML
  class ApplicationController < ActionController::Base
    helper EasyML::ApplicationHelper

    include InertiaRails::Controller
    layout "easy_ml/application"

    protect_from_forgery with: :exception

    before_action :hot_reload

    def hot_reload
      return unless Rails.env.development? && ENV["EASY_ML_DEMO_APP"]

      Dir[EasyML::Engine.root.join("lib/**/*")].select { |f| Pathname.new(f).extname == ".rb" }.each do |file|
        load file
      end
    end

    def settings_to_json(settings)
      SettingsSerializer.new(settings).serializable_hash.dig(:data, :attributes)
    end

    def dataset_to_json(dataset)
      DatasetSerializer.new(dataset).serializable_hash.dig(:data, :attributes)
    end

    def datasource_to_json(datasource)
      DatasourceSerializer.new(datasource).serializable_hash.dig(:data, :attributes)
    end

    def model_to_json(model)
      ModelSerializer.new(model).serializable_hash.dig(:data, :attributes)
    end

    def retraining_job_to_json(job)
      RetrainingJobSerializer.new(job).serializable_hash.dig(:data, :attributes)
    end

    def retraining_run_to_json(run)
      RetrainingRunSerializer.new(run).serializable_hash.dig(:data, :attributes)
    end

    def easy_ml_root
      Rails.application.routes.routes.find { |r| r.app.app == EasyML::Engine }&.path&.spec&.to_s
    end

    inertia_share do
      flash_messages = []

      flash_messages << { type: "success", message: flash[:notice] } if flash[:notice]

      flash_messages << { type: "error", message: flash[:alert] } if flash[:alert]

      flash_messages << { type: "info", message: flash[:info] } if flash[:info]

      {
        rootPath: easy_ml_root,
        url: request.path.gsub(Regexp.new(easy_ml_root), ""),
        errors: session.delete(:errors) || {},
        flash: flash_messages,
      }
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc39 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc38 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc37 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc36 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc35 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc34 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc33 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc32 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc31 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc30 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc29 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc28 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc27 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc26 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc25 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc24 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc22 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc21 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc20 app/controllers/easy_ml/application_controller.rb
easy_ml-0.2.0.pre.rc19 app/controllers/easy_ml/application_controller.rb