Sha256: 4c952b0798186f2a4a68c3199e78287742937accad6e1b5f66f6b7e76def7e02

Contents?: true

Size: 1.25 KB

Versions: 122

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  #
  # This class handles all logic regarding registering menus
  #
  class MenuRegistry
    class << self
      #
      # Finds a menu by name or creates it if it doesn't exist. Optionally,
      # registers a MenuItem DSL block for the menu.
      #
      # @param name [Symbol] Name of the menu
      # @param &block [Menu] Registration body of the menu. It's stored to be
      #                      evaluated at rendering time
      #
      def register(name, &block)
        menu = find(name) || create(name)

        menu.configurations << block

        menu
      end

      #
      # Finds a menu by name
      #
      # @param name [Symbol] The name of the menu
      #
      def find(name)
        all[name]
      end

      #
      # Creates an empty named menu
      #
      # @param name [Symbol] The name of the menu
      #
      def create(name)
        all[name] = new
      end

      #
      # Destroys a named menu
      #
      # @param name [Symbol] The name of the menu
      #
      def destroy(name)
        all[name] = nil
      end

      private

      def all
        @all ||= {}
      end
    end

    attr_reader :configurations

    def initialize
      @configurations = []
    end
  end
end

Version data entries

122 entries across 122 versions & 2 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/menu_registry.rb
decidim-core-0.27.8 lib/decidim/menu_registry.rb
decidim-core-0.27.7 lib/decidim/menu_registry.rb
decidim-core-0.27.6 lib/decidim/menu_registry.rb
decidim-core-0.26.10 lib/decidim/menu_registry.rb
decidim-core-0.26.9 lib/decidim/menu_registry.rb
decidim-core-0.27.5 lib/decidim/menu_registry.rb
decidim-core-0.26.8 lib/decidim/menu_registry.rb
decidim-core-0.27.4 lib/decidim/menu_registry.rb
decidim-core-0.27.3 lib/decidim/menu_registry.rb
decidim-core-0.26.7 lib/decidim/menu_registry.rb
decidim-core-0.26.5 lib/decidim/menu_registry.rb
decidim-core-0.27.2 lib/decidim/menu_registry.rb
decidim-core-0.27.1 lib/decidim/menu_registry.rb
decidim-core-0.26.4 lib/decidim/menu_registry.rb
decidim-core-0.27.0 lib/decidim/menu_registry.rb
decidim-core-0.26.3 lib/decidim/menu_registry.rb
decidim-core-0.27.0.rc2 lib/decidim/menu_registry.rb
decidim-core-0.27.0.rc1 lib/decidim/menu_registry.rb
decidim-core-0.26.2 lib/decidim/menu_registry.rb