Skip to content

Commit

Permalink
Use kwargs within Navigation classes (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz authored Aug 28, 2024
1 parent b325561 commit 12e8dd8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
13 changes: 4 additions & 9 deletions lib/trestle/navigation/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/trestle/navigation/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/trestle/navigation/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 12e8dd8

Please sign in to comment.