Sha256: dc0ec38d341a6857a2aa6ad04e5f021d86ba8984a13a1b30cafd5d3cece7a788

Contents?: true

Size: 920 Bytes

Versions: 3

Compression:

Stored size: 920 Bytes

Contents

# frozen_string_literal: true

module LinkedRails
  module Enhancements
    module Menuable
      module Model
        extend ActiveSupport::Concern

        def menus(user_context = nil)
          menu_list(user_context).menus
        end

        def menu(tag, user_context = nil)
          menu_list(user_context).menu(tag)
        end

        def menu_list(user_context = nil)
          @menu_list = {}
          @menu_list[user_context] ||= self.class.menu_class.new(resource: self, user_context: user_context)
        end

        module ClassMethods
          def menu_class
            @menu_class ||= "#{name}MenuList".safe_constantize || "#{superclass.name}MenuList".safe_constantize
          end

          def preview_includes
            return super if menu_class.blank?

            super + menu_class.defined_menus.keys.map { |tag| "#{tag}_menu" }
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
linked_rails-0.0.3 lib/linked_rails/enhancements/menuable/model.rb
linked_rails-0.0.2 lib/linked_rails/enhancements/menuable/model.rb
linked_rails-0.0.1 lib/linked_rails/enhancements/menuable/model.rb