Sha256: f120d2e565304c54e7411b52e465252bb045e7369de91a46c8a0141cb09d5c22

Contents?: true

Size: 796 Bytes

Versions: 5

Compression:

Stored size: 796 Bytes

Contents

class MenuItem
  attr_reader :name, :path, :namespace

  def initialize(namespace, path)
    @namespace = namespace
    @path = path
    @name = path.humanize
  end

  def url
    "/#{namespace}/#{path}"
  end
end


class Menu
  attr_reader :namespace

  def initialize(namespace)
    @namespace = namespace
  end

  def routes
    @routes ||= Rails.application.routes.routes
  end

  def menu_routes
    @menu_routes ||= routes.select { |r| r.defaults[:action] == 'index' }
  end

  def specs
    @specs ||= menu_routes.map { |r| r.path.spec }.uniq
  end

  def menu_items
    @menu_items = []
    specs.each do |s| 
      matches = /\/#{@namespace}\/(\w*)/.match(s.to_s) 
      @menu_items << matches[1] if matches
    end
    @menu_items.uniq.map { |i| MenuItem.new(@namespace, i) }
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
app_frame-0.6.1 app/models/menu.rb
app_frame-0.5.8 app/models/menu.rb
app_frame-0.5.7 app/models/menu.rb
app_frame-0.5.6 app/models/menu.rb
app_frame-0.5.5 app/models/menu.rb