README.md in tiny_sweeper-0.0.4 vs README.md in tiny_sweeper-0.0.5

- old
+ new

@@ -9,32 +9,34 @@ ## How Do I Use It? ```ruby class Sundae - attr_accessor :topping + attr_accessor :ice_cream, :topping include TinySweeper - sweep(:topping) { |topping| topping.strip.downcase } + sweep(:ice_cream, :topping) { |flavor| flavor.strip.downcase } end ``` Now your Sundae toppings will be tidied up: ```ruby dessert = Sundae.new +dessert.ice_cream = ' CHOCOlate ' dessert.topping = ' ButTTERscotCH ' -dessert.topping #=> 'butterscotch'. Tidy! +dessert.ice_cream #=> 'chocolate'. Tidy! +dessert.topping #=> 'butterscotch'. Tidy! ``` TinySweeper will not bother you about your nil values; they're your job to handle. ```ruby Sundae.new.topping = nil # No topping? TinySweeper won't sweep it. ``` -If you have an object with lots of attributes that need cleaning, you can do that, too: +If you have an object with lots of attributes that need cleaning (because, say, they were loaded from the database), you can do that, too: ```ruby dessert.sweep_up! # or: Sundae.sweep_up!(dessert) @@ -42,12 +44,10 @@ ### Future Ideas Just spit-balling here... -It'd be nice to define sweep-ups for multiple fields. - If you often sweep up fields in the same way - say, squishing and nilifying blanks - it'd be nice to bundle that up in some way, so you don't have to repeat yourself. Something like this might be nice: ```ruby # in config/initializers/tiny_sweeper.rb, or similar: TinySweeper.sweep_style(:squish_and_nil_blanks) { |value| @@ -70,22 +70,25 @@ end ``` #### Other Ways to Sweep -Rails models are clearly the natural use-case for this. So it would make sense to have an easy way to auto-clean up models in a table. We'll see. +Rails models are clearly the natural use-case for this. So it would make sense to have an easy way to auto-clean up models in a table. We'll see. Right now, this works (though it's slow): +```ruby +MyModel.find_each do |m| + m.sweep_up! + m.save +end +``` + ## How Does It Work? You include the `TinySweeper` module in your class, and define some sweep-up rules on your class' attributes. It prepends an anonymous module to your class, adds to it a method with the same name that cleans its input according to the sweep-up rule, and then passes the cleaned value to `super`. "Why not use `after_create` or `before_save` or `before_validate` callbacks?" -That's one approach, and it's used by [nilify_blanks](https://github.com/rubiety/nilify_blanks), so it's clearly workable. - -But it means your data isn't cleaned until the callback runs; TinySweeper cleans your data as soon as it arrives. - -Also, it requires rails, so you can't use it outside of rails. +That's one approach, and it's used by [nilify_blanks](https://github.com/rubiety/nilify_blanks), so it's clearly workable. But it means your data isn't cleaned until the callback runs; TinySweeper cleans your data as soon as it arrives. Also, it requires rails, so you can't use it outside of rails. ## Install It The standard: