Sha256: 8bf97d38da905b70a745464702469bb5f94cdbd448d7ff80f6be21bc4a3edfae
Contents?: true
Size: 1.56 KB
Versions: 39
Compression:
Stored size: 1.56 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] ||= {} models.each do |model| if model.class == Class || model.class == String @available_models[project][role].merge! model.to_s => %i[index show update create destroy] elsif model.class == Hash @available_models[project][role].merge! model end end @available_models = @available_models.with_indifferent_access end def available_models_for(project, role: :admin) project = project.underscore.to_sym unless project.is_a? Symbol 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&.dig(dependency, role).present? @available_models&.dig(dependency, role).keys 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 # TODO: somehow cache results? models.map do |model| model.class == String ? model.constantize : model end end def available_models(role:) models_array models_type: :available, role: role end end
Version data entries
39 entries across 39 versions & 1 rubygems