codeplant / simple-navigation

A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
http://simple-navigation-demo.codeplant.ch/
MIT License
885 stars 136 forks source link

Item refactoring #161

Closed simonc closed 10 years ago

simonc commented 10 years ago

This PR reduces Item's dependencies and public API.

An important change is the way an item impacts its container. Calling Item.new should not cause the item's container to be modified. The container is now touched only when calling container.item ... or container.items = .... It moves the responsibility from Item to ItemContainer where it belongs.

simonc commented 10 years ago

@andi Do you want to review the PR or may I merge it?

andi commented 10 years ago

do we break the API with it?

simonc commented 10 years ago

Yes, it removes the Item#autogenerate_item_ids? method and changes Item behavior. The real change is that the following code will not modify the container:

container = ItemContainer.new
item = Item.new(container, :key, 'url', 'name', container_id: 'hello')

while this two examples will:

container = ItemContainer.new
item = Item.new(container, :key, 'url', 'name', container_id: 'hello')
container.items = [item] # changes container id

container.item :key, 'url', 'name', container_id: 'hello' # changes container id
andi commented 10 years ago

fine with me, go ahead and merge :-)

On Tue, Apr 1, 2014 at 3:05 PM, Simon Courtois notifications@github.comwrote:

Yes, it removes the Item#autogenerate_item_ids? method and changes Item behavior. The real change is that the following code will not modify the container:

container = ItemContainer.newitem = Item.new(container, :key, 'url', 'name', container_id: 'hello')

while this two examples will:

container = ItemContainer.newitem = Item.new(container, :key, 'url', 'name', container_id: 'hello')container.items = [item] # changes container id container.item :key, 'url', 'name', container_id: 'hello' # changes container id

— Reply to this email directly or view it on GitHubhttps://github.com/codeplant/simple-navigation/pull/161#issuecomment-39202330 .

simonc commented 10 years ago

Great! I'll try to be clearer about side effects for next PRs ;)

simonc commented 10 years ago

Damn! I need to add integration tests. In my issue-testing-app something is broken. I'll dig into it and fix it.

simonc commented 10 years ago

Fixed.