From 12e8dd86aaa57b505c0aaba2b824c130e1125213 Mon Sep 17 00:00:00 2001 From: Sam Pohlenz Date: Wed, 28 Aug 2024 15:40:10 +0930 Subject: [PATCH] Use kwargs within Navigation classes (#478) --- lib/trestle/navigation/block.rb | 13 ++++--------- lib/trestle/navigation/group.rb | 4 ++-- lib/trestle/navigation/item.rb | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/trestle/navigation/block.rb b/lib/trestle/navigation/block.rb index 06daf253..0923dacf 100644 --- a/lib/trestle/navigation/block.rb +++ b/lib/trestle/navigation/block.rb @@ -28,12 +28,7 @@ def default_path @admin ? @admin.path : nil end - def item(name, path=nil, options={}) - if path.is_a?(Hash) - options = path - path = nil - end - + def item(name, path=nil, **options) if options[:group] group = Group.new(options[:group]) elsif @current_group @@ -43,11 +38,11 @@ def item(name, path=nil, options={}) options = options.merge(group: group) if group options = options.merge(admin: @admin) if @admin - items << Item.new(name, path || default_path, options) + items << Item.new(name, path || default_path, **options) end - def group(name, options={}) - @current_group = Group.new(name, options) + def group(name, **options) + @current_group = Group.new(name, **options) yield ensure @current_group = nil diff --git a/lib/trestle/navigation/group.rb b/lib/trestle/navigation/group.rb index bce785f2..71eaeb91 100644 --- a/lib/trestle/navigation/group.rb +++ b/lib/trestle/navigation/group.rb @@ -3,7 +3,7 @@ class Navigation class Group attr_reader :name, :options - def initialize(name, options={}) + def initialize(name, **options) @name, @options = name.to_s, options end @@ -26,7 +26,7 @@ def <=>(other) end def merge(other) - self.class.new(name, options.merge(other.options)) + self.class.new(name, **options.merge(other.options)) end def priority diff --git a/lib/trestle/navigation/item.rb b/lib/trestle/navigation/item.rb index af51af0e..f1681341 100644 --- a/lib/trestle/navigation/item.rb +++ b/lib/trestle/navigation/item.rb @@ -3,7 +3,7 @@ class Navigation class Item attr_reader :name, :path, :options - def initialize(name, path=nil, options={}) + def initialize(name, path=nil, **options) @name, @path, @options = name.to_s, path, options end