module Decidim

Decidim configuration.

Decidim configuration.

Public Class Methods

component_manifests() click to toggle source

Public: Finds all registered component manifest's via the `register_component` method.

Returns an Array.

# File lib/decidim/core.rb, line 453
def self.component_manifests
  component_registry.manifests
end
component_registry() click to toggle source

Public: Stores the registry of components

# File lib/decidim/core.rb, line 495
def self.component_registry
  @component_registry ||= ManifestRegistry.new(:components)
end
content_blocks() click to toggle source

Public: Stores an instance of ContentBlockRegistry

# File lib/decidim/core.rb, line 534
def self.content_blocks
  @content_blocks ||= ContentBlockRegistry.new
end
find_component_manifest(name) click to toggle source

Public: Finds a component manifest by the component's name.

name - The name of the ComponentManifest to find.

Returns a ComponentManifest if found, nil otherwise.

# File lib/decidim/core.rb, line 470
def self.find_component_manifest(name)
  component_registry.find(name.to_sym)
end
find_participatory_space_manifest(name) click to toggle source

Public: Finds a participatory space manifest by the participatory space's name.

name - The name of the ParticipatorySpaceManifest to find.

Returns a ParticipatorySpaceManifest if found, nil otherwise.

# File lib/decidim/core.rb, line 480
def self.find_participatory_space_manifest(name)
  participatory_space_registry.find(name.to_sym)
end
find_resource_manifest(resource_name_or_klass) click to toggle source

Public: Finds a resource manifest by the resource's name.

resource_name_or_class - The String of the ResourceManifest name or the class of the ResourceManifest model_class to find.

Returns a ResourceManifest if found, nil otherwise.

# File lib/decidim/core.rb, line 490
def self.find_resource_manifest(resource_name_or_klass)
  resource_registry.find(resource_name_or_klass)
end
global_engines() click to toggle source

Public: Finds all registered engines via the 'register_global_engine' method.

Returns an Array

# File lib/decidim/core.rb, line 401
def self.global_engines
  @global_engines ||= {}
end
machine_translation_service_klass() click to toggle source
# File lib/decidim/core.rb, line 576
def self.machine_translation_service_klass
  return unless Decidim.enable_machine_translations

  Decidim.machine_translation_service.to_s.safe_constantize
end
menu(name, &block) click to toggle source

Public: Registers configuration for a new or existing menu

name - A string or symbol with the name of the menu &block - A block using the DSL defined in `Decidim::MenuItem`

metrics_operation() click to toggle source

Public: Stores an instance of MetricOperation

# File lib/decidim/core.rb, line 549
def self.metrics_operation
  @metrics_operation ||= MetricOperation.new
end
metrics_registry() click to toggle source

Public: Stores an instance of MetricRegistry

# File lib/decidim/core.rb, line 544
def self.metrics_registry
  @metrics_registry ||= MetricRegistry.new
end
organization_settings(model) click to toggle source

Public: Returns the correct settings object for the given organization or the default settings object when the organization cannot be determined. The model to be passed to this method can be any model that responds to the `organization` method or the organization itself. If the given model is not an organization or does not respond to the organization method, returns the default organization settings.

model - The target model for which to fetch the settings object, either an

organization or a model responding to the `organization` method.
# File lib/decidim/core.rb, line 563
def self.organization_settings(model)
  organization = begin
    if model.is_a?(Decidim::Organization)
      model
    elsif model.respond_to?(:organization) && model.organization.present?
      model.organization
    end
  end
  return Decidim::OrganizationSettings.defaults unless organization

  Decidim::OrganizationSettings.for(organization)
end
participatory_space_manifests() click to toggle source

Public: Finds all registered participatory space manifest's via the `register_participatory_space` method.

Returns an Array.

# File lib/decidim/core.rb, line 461
def self.participatory_space_manifests
  participatory_space_registry.manifests
end
participatory_space_registry() click to toggle source

Public: Stores the registry of participatory spaces

# File lib/decidim/core.rb, line 500
def self.participatory_space_registry
  @participatory_space_registry ||= ManifestRegistry.new(:participatory_spaces)
end
permissions_registry() click to toggle source

Public: Stores the registry for user permissions

# File lib/decidim/core.rb, line 510
def self.permissions_registry
  @permissions_registry ||= PermissionsRegistry.new
end
register_component(name, &block) click to toggle source

Public: Registers a component, usually held in an external library or in a separate folder in the main repository. Exposes a DSL defined by `Decidim::ComponentManifest`.

Component manifests are held in a global registry and are used in all kinds of places to figure out what new components or functionalities the component provides.

name - A Symbol with the component's unique name.

Returns nothing.

# File lib/decidim/core.rb, line 415
def self.register_component(name, &block)
  component_registry.register(name, &block)
end
register_global_engine(name, engine, options = {}) click to toggle source

Public: Registers a global engine. This method is intended to be used by component engines that also offer unscoped functionality

name - The name of the engine to register. Should be unique. engine - The engine to register. options - Options to pass to the engine.

:at - The route to mount the engine to.

Returns nothing.

# File lib/decidim/core.rb, line 377
def self.register_global_engine(name, engine, options = {})
  return if global_engines.has_key?(name)

  options[:at] ||= "/#{name}"

  global_engines[name.to_sym] = {
    at: options[:at],
    engine: engine
  }
end
register_participatory_space(name, &block) click to toggle source

Public: Registers a participatory space, usually held in an external library or in a separate folder in the main repository. Exposes a DSL defined by `Decidim::ParticipatorySpaceManifest`.

Participatory space manifests are held in a global registry and are used in all kinds of places to figure out what new components or functionalities the participatory space provides.

name - A Symbol with the participatory space's unique name.

Returns nothing.

# File lib/decidim/core.rb, line 430
def self.register_participatory_space(name, &block)
  participatory_space_registry.register(name, &block)
end
register_resource(name, &block) click to toggle source

Public: Registers a resource.

Returns nothing.

# File lib/decidim/core.rb, line 437
def self.register_resource(name, &block)
  resource_registry.register(name, &block)
end
resource_manifests() click to toggle source

Public: Finds all registered resource manifests via the `register_component` method.

Returns an Array.

# File lib/decidim/core.rb, line 445
def self.resource_manifests
  resource_registry.manifests
end
resource_registry() click to toggle source

Public: Stores the registry of resource spaces

# File lib/decidim/core.rb, line 505
def self.resource_registry
  @resource_registry ||= ManifestRegistry.new(:resources)
end
seed!() click to toggle source

Loads seeds from all engines.

# File lib/decidim/core.rb, line 101
def self.seed!
  # Faker needs to have the `:en` locale in order to work properly, so we
  # must enforce it during the seeds.
  original_locale = I18n.available_locales
  I18n.available_locales = original_locale + [:en] unless original_locale.include?(:en)

  Rails.application.railties.to_a.uniq.each do |railtie|
    next unless railtie.respond_to?(:load_seed) && railtie.class.name.include?("Decidim::")

    railtie.load_seed
  end

  participatory_space_manifests.each do |manifest|
    manifest.seed!

    Organization.all.each do |organization|
      ContextualHelpSection.set_content(
        organization,
        manifest.name,
        Decidim::Faker::Localized.wrapped("<p>", "</p>") do
          Decidim::Faker::Localized.sentence(word_count: 15)
        end
      )
    end
  end

  Gamification.badges.each do |badge|
    puts "Setting random values for the \"#{badge.name}\" badge..."
    User.all.find_each do |user|
      Gamification::BadgeScore.find_or_create_by!(
        user: user,
        badge_name: badge.name,
        value: Random.rand(0...20)
      )
    end
  end

  I18n.available_locales = original_locale
end
stats() click to toggle source

Public: Stores an instance of StatsRegistry

# File lib/decidim/core.rb, line 515
def self.stats
  @stats ||= StatsRegistry.new
end
traceability() click to toggle source

Public: Stores an instance of Traceability

# File lib/decidim/core.rb, line 539
def self.traceability
  @traceability ||= Traceability.new
end
unregister_global_engine(name) click to toggle source

Semiprivate: Removes a global engine from the registry. Mostly used on testing, no real reason to use this on production.

name - The name of the global engine to remove.

Returns nothing.

# File lib/decidim/core.rb, line 394
def self.unregister_global_engine(name)
  global_engines.delete(name.to_sym)
end
view_hooks() click to toggle source

Public: Stores an instance of ViewHooks

# File lib/decidim/core.rb, line 529
def self.view_hooks
  @view_hooks ||= ViewHooks.new
end