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.15.0 lib/decidim/menu_registry.rb
decidim-core-0.14.4 lib/decidim/menu_registry.rb
decidim-core-0.14.3 lib/decidim/menu_registry.rb
decidim-core-0.14.2 lib/decidim/menu_registry.rb
decidim-core-0.14.1 lib/decidim/menu_registry.rb
decidim-core-0.13.1 lib/decidim/menu_registry.rb
decidim-core-0.12.2 lib/decidim/menu_registry.rb
decidim-core-0.13.0 lib/decidim/menu_registry.rb
decidim-core-0.12.1 lib/decidim/menu_registry.rb
decidim-core-0.13.0.pre1 lib/decidim/menu_registry.rb
decidim-core-0.12.0 lib/decidim/menu_registry.rb
decidim-core-0.11.2 lib/decidim/menu_registry.rb
decidim-core-0.12.0.pre lib/decidim/menu_registry.rb
decidim-core-0.11.1 lib/decidim/menu_registry.rb
decidim-core-0.11.0.pre1 lib/decidim/menu_registry.rb
decidim-core-0.10.1 lib/decidim/menu_registry.rb
decidim-core-0.10.0 lib/decidim/menu_registry.rb
decidim-core-0.9.3 lib/decidim/menu_registry.rb
decidim-core-0.9.2 lib/decidim/menu_registry.rb
decidim-core-0.9.1 lib/decidim/menu_registry.rb