Skip to content

Reduce the surface area of Spree::Stock::Coordinator#950

Closed
jordan-brough wants to merge 2 commits intosolidusio:masterfrom
jordan-brough:reduce-coordinator-surface-area
Closed

Reduce the surface area of Spree::Stock::Coordinator#950
jordan-brough wants to merge 2 commits intosolidusio:masterfrom
jordan-brough:reduce-coordinator-surface-area

Conversation

@jordan-brough
Copy link
Copy Markdown
Contributor

Make 'shipments' the only public method of the Coordinator. It's the
only method called on Coordinator outside of the specs.

This was prompted by me looking at the Coordinator code while
reviewing some of the taxes work and thinking it might be nice to
refactor it a bit, which is easier with a reduced surface area.

Make 'shipments' the only public method of the Coordinator. It's the
only method called on Coordinator outside of the specs.

This was prompted by me looking at the Coordinator code while
reviewing some of the taxes work and thinking it might be nice to
refactor it a bit, which is easier with a reduced surface area.
expect(packages.map(&:quantity).sum).to eq(5)
expect(packages.flat_map(&:contents).map(&:inventory_unit).uniq.size).to eq(5)
expect(shipments).not_to be_empty
inventory_units = shipments.flat_map { |s| s.inventory_units }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass &:inventory_units as an argument to flat_map instead of a block.

@mamhoff
Copy link
Copy Markdown
Contributor

mamhoff commented Mar 3, 2016

I like this. This would mean that the shipping rates estimation could be part of the to_shipment method on the package class, and I could get rid of the strange attr_accessor in Spree::ShippingRate.

@cbrunsdon
Copy link
Copy Markdown
Contributor

I also like this but reckon it will need a changelog if it goes in, as we are technically immediately removing a method from the public API.

I have such a poor understanding of what a "package" does I'd rather this be the only thing accessible by a co-ordinator, and agree it would give us more flexibility to (eventually) make some meaningful changes behind the scenes if we can get this in.

@jhawthorn
Copy link
Copy Markdown
Contributor

I wouldn't mind #packages being public, as I could see that being useful, but I don't feel that strongly.

👍

@jordan-brough
Copy link
Copy Markdown
Contributor Author

Great! I added a changelog entry.

jordan-brough added a commit that referenced this pull request Mar 4, 2016
…-area

Reduce the surface area of Spree::Stock::Coordinator
@jordan-brough
Copy link
Copy Markdown
Contributor Author

Merged in f8b889a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants