Sha256: 0c5615cb7d005e8c42273f467838cf3d2b88404ae7e4333740f2c40524ff90e7

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Tramway::Admin::RecordsModels
  def set_available_models(*models, project:, role: :admin)
    @available_models ||= {}
    @available_models[project] ||= {}
    @available_models[project][role] ||= []
    @available_models[project][role] += models
    @available_models = @available_models.with_indifferent_access
  end

  def available_models_for(project, role: :admin)
    models = get_models_by_key(@available_models, project, role)
    if project_is_engine?(project)
      models += engine_class(project).dependencies.map do |dependency|
        if @available_models[dependency][role].present?
          @available_models[dependency][role]
        else
          error = Tramway::Error.new(
            plugin: :admin,
            method: :available_models_for,
            message: "There is no dependency `#{dependency}` for plugin: #{project}. Please, check file `tramway-#{project}/lib/tramway/#{project}/#{project}.rb`"
          )
          raise error
        end
      end.flatten.compact
    end
    models
  end

  def available_models(role:)
    models_array models_type: :available, role: role
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tramway-admin-1.23.0.2 lib/tramway/admin/records_models.rb
tramway-admin-1.23.0.1 lib/tramway/admin/records_models.rb
tramway-admin-1.23 lib/tramway/admin/records_models.rb
tramway-admin-1.22.0.4 lib/tramway/admin/records_models.rb
tramway-admin-1.22.0.3 lib/tramway/admin/records_models.rb
tramway-admin-1.22.0.2 lib/tramway/admin/records_models.rb
tramway-admin-1.22.0.1 lib/tramway/admin/records_models.rb
tramway-admin-1.22 lib/tramway/admin/records_models.rb
tramway-admin-1.21.2 lib/tramway/admin/records_models.rb