Module: Tramway::Api::SingletonModels

Included in:
Tramway::Api
Defined in:
lib/tramway/api/singleton_models.rb

Instance Method Summary collapse

Instance Method Details

#set_singleton_models(*models, project:, role: :open) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tramway/api/singleton_models.rb', line 4

def set_singleton_models(*models, project:, role: :open)
  @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

#singleton_models(role:) ⇒ Object



28
29
30
# File 'lib/tramway/api/singleton_models.rb', line 28

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

#singleton_models_for(project, role: :open) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/tramway/api/singleton_models.rb', line 18

def singleton_models_for(project, role: :open)
  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