README.md in basket-0.0.6 vs README.md in basket-0.0.7

- old
+ new

@@ -20,10 +20,11 @@ If bundler is not being used to manage dependencies, install the gem by executing: $ gem install basket ## Usage +### Adding Add items to your basket as they come along. They might come along quickly, or there might be a delay between them. Regardless, you want to collect items into your basket before going and doing something with them. ```ruby while chicken.laying? do @@ -32,10 +33,14 @@ end ``` The item added to the basket can be any data you want! If you are using the in memory Queue, it is fine to store Ruby objects, but if you have a different backend, must be JSON serializable via `to_json`. +### Your basket + +When a basket has become full after you have added a bunch of things to it, it performs actions! See below for the full definition of a basket. + ```ruby class QuicheBasket # Include the Basket::Batcher include Basket::Batcher @@ -82,10 +87,55 @@ The `on_failure` use of `batch` of course may not have a full batch as the error could have been generated during `add` or `on_add`. The `on_failure` callback also has access to an `error` variable which holds the error that was generated. Defining `on_add`, `on_failure`, and `on_success` is optional. +### Search + +You may search through your basket, if for example, you need to see if you've accidentally collected a robin egg and not a chicken egg! + +```ruby +search_results = Basket.search("QuicheBasket") do |egg| + egg.color == "blue" +end +``` + +The block you pass will match against the objects in your basket. If you have ruby objects in your basket, you can match against their properties just as if you were accessing them one at a time. If you have json objects in your basket, you will be searching through a hash thusly: + +```ruby +search_results = Basket.search("PlaylistBasket") do |song| + song[:artist] == "Vansire" +end +``` + +The search results will be a fully qualified basket element which will contain an id attribute and a data attribute. In the case of using the MemoryBackend, you might see something like this: + +```ruby +# ...continued from above +search_results.first #=> #<Basket::Element:0x00000001075d9c80 + # @data=#<Egg color="blue", size="smol"> + # @id="5fe3df9e-4063-4b67-a08f-e36b847087c7"> +``` + +You'll note that the result of a search is an array of basket elements. An element consists of the data that you put in and ID. What is the id for? Glad you asked. + +### Remove + +You can also remove something from your basket. Perhaps it is deleted in the database and no longer contains a valid reference to data? Perhaps you found that robin egg and don't actually want to use it to make a quiche, because who would? Either way, removing the element is easy! + +```ruby +# ...continued from above +element_id_to_remove = search_results.first +removed_egg = Basket.remove('Quiche', element_id_to_remove) +removed_egg #=> #<Egg color="blue", size="smol"> +``` + +Voila! + +### A Note of Warning + +Searching for and removing elements from your basket is an inherently tricky process as your basket may fill up and execute the `perform` action while searching and removing. ## Configuration In an initializer, or somewhere equally appropriate, you might put something like this: ```ruby @@ -130,7 +180,13 @@ ## Code of Conduct Everyone interacting in the Basket project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nicholalexander/basket/blob/main/CODE_OF_CONDUCT.md). +## Thanks +This project has been a fun and educational use of Growth Time at [Test Double](https://testdouble.com/) where consultants are given 4hrs per week to grow their skills and work on projects that further the mission of building software, better. +## Authors + +* [Nichol Alexander](https://github.com/nicholalexander/) +* [Alec Clarke](https://github.com/alecclarke) \ No newline at end of file