Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global hash of Menu instances. #1453

Merged
merged 1 commit into from Mar 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 2 additions & 18 deletions core/lib/refinery/menu.rb
@@ -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
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