Skip to content

Commit

Permalink
Remove global hash of Menu instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
phiggins committed Mar 22, 2012
1 parent 85f9a04 commit b9291bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
20 changes: 2 additions & 18 deletions core/lib/refinery/menu.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
module Refinery

# Create a little something to store the instances of the menu.
class << self
attr_accessor :menus
def menus
@@menus ||= HashWithIndifferentAccess.new
end
end

class Menu

def initialize(objects = nil)
objects.each do |item|
item = item.to_refinery_menu_item if item.respond_to?(:to_refinery_menu_item)
items << MenuItem.new(item.merge(:menu_id => id))
items << MenuItem.new(item.merge(:menu => self))
end if objects

::Refinery.menus[self.id] = self
end

attr_accessor :items, :id

def id
require 'securerandom' unless defined?(::SecureRandom)
@id ||= ::SecureRandom.hex(8)
end
attr_accessor :items

def items
@items ||= []
Expand Down
6 changes: 1 addition & 5 deletions core/lib/refinery/menu_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class MenuItem < HashWithIndifferentAccess

class << self
def attributes
[:title, :parent_id, :lft, :rgt, :depth, :url, :menu_id, :menu_match]
[:title, :parent_id, :lft, :rgt, :depth, :url, :menu, :menu_match]
end

def apply_attributes!
Expand Down Expand Up @@ -77,10 +77,6 @@ def inspect
hash.inspect
end

def menu
::Refinery.menus[menu_id]
end

def parent
@parent ||= (menu.detect{|item| item.original_type == original_type && item.original_id == parent_id} if has_parent?)
end
Expand Down

0 comments on commit b9291bc

Please sign in to comment.