Sha256: 6c22aa9a91480011cf4e562371e7dec16390b621a4abadbb295edb14b5a5f001

Contents?: true

Size: 734 Bytes

Versions: 23

Compression:

Stored size: 734 Bytes

Contents

module ActiveAdmin
  class Menu
    
    def initialize
      @items = []
      yield(self) if block_given?
    end  
    
    def add(*args, &block)
      @items << MenuItem.new(*args, &block)
    end
    
    def [](name)
      items.find{ |i| i.name == name }
    end
    
    def items
      @items.sort
    end
    
    def find_by_url(url)
      recursive_find_by_url(items, url)
    end
    
    private
    
    def recursive_find_by_url(collection, url)
      found = nil
      collection.each do |item|
        if item.url == url
          found = item
          break
        else
          found = recursive_find_by_url(item.children, url)
          break if found
        end
      end
      found
    end
    
  end
end

Version data entries

23 entries across 23 versions & 4 rubygems

Version Path
activeadmin-0.2.0 lib/active_admin/menu.rb
activeadmin-0.1.1 lib/active_admin/menu.rb
activeadmin-0.1.0 lib/active_admin/menu.rb