Skip to content

Commit

Permalink
Remove little duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Francois committed Aug 5, 2013
1 parent 30b135f commit 44500de
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/publify_login_system/access_control.rb
Expand Up @@ -100,16 +100,12 @@ def initialize(name, controller=nil)
end

def menu(name, url, options={})
if url.is_a?(Hash)
url[:controller].nil? ? url[:controller] = @controllers.first : @controllers << url[:controller]
end
url = set_controller_from_url(url)
@menus << Menu.new(name, url, options)
end

def submenu(name, url, options={})
if url.is_a?(Hash)
url[:controller].nil? ? url[:controller] = @controllers.first : @controllers << url[:controller]
end
url = set_controller_from_url(url)
@submenus << Menu.new(name, url, options)
end

Expand All @@ -120,6 +116,14 @@ def human_name
def uid
@name.to_s.downcase.gsub(/[^a-z0-9]+/, '').gsub(/-+$/, '').gsub(/^-+$/, '')
end

private

def set_controller_from_url(url)
return url unless url.is_a?(Hash)
url[:controller].nil? ? url[:controller] = @controllers.first : @controllers << url[:controller]
url
end
end

class Menu
Expand Down

0 comments on commit 44500de

Please sign in to comment.