Sha256: 27106a85990792fad45ace64430823b3636a7db77675bd6d1318eec1836bfda4

Contents?: true

Size: 990 Bytes

Versions: 15

Compression:

Stored size: 990 Bytes

Contents

# frozen_string_literal: true

module Tramway::Admin::SingletonModels
  def set_singleton_models(*models, project:, role: :admin)
    @singleton_models ||= {}
    @singleton_models[project] ||= {}
    @singleton_models[project][role] ||= {}
    models.each do |model|
      if model.class == Class
        @singleton_models[project][role].merge! model => %i[index show update create destroy]
      elsif model.class == Hash
        @singleton_models[project][role].merge! model
      end
    end
    @singleton_models = @singleton_models.with_indifferent_access
  end

  def singleton_models_for(project, role: :admin)
    models = get_models_by_key(@singleton_models, project, role)
    if project_is_engine?(project)
      models += engine_class(project).dependencies.map do |dependency|
        @singleton_models&.dig(dependency, role)&.keys
      end.flatten.compact
    end
    models
  end

  def singleton_models(role:)
    models_array models_type: :singleton, role: role
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
tramway-admin-1.29.1.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.29.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.29 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.2.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.2 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.1.5 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.1.4 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.1.3 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.1.2 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28.0.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.28 lib/tramway/admin/singleton_models.rb
tramway-admin-1.27.0.2 lib/tramway/admin/singleton_models.rb
tramway-admin-1.27.0.1 lib/tramway/admin/singleton_models.rb
tramway-admin-1.27 lib/tramway/admin/singleton_models.rb