README.md in exec_if-0.2.0 vs README.md in exec_if-0.3.0
- old
+ new
@@ -22,21 +22,30 @@
```ruby
require 'exec_if'
[1, 2, 3, 4, 5].map do |i|
- i.exec_if(i.even?) {|even| 'even' }
+ i.exec_if(i.even?) { 'even' }
end # => [1, 'even', 3, 'even', 5]
```
It is especially useful for long method chains.
```ruby
Item.active.
- exec_if(params[:published_to].presence) {|item, published_to| item.where(published_at: nil..published_to) }.
- exec_if(params[:name].presence) {|item, name| item.where("name LIKE ?", "%#{name}%")}.
+ exec_if(params[:published_to].present?) { where(published_at: nil..params[:published_to]) }.
+ exec_if(params[:name].present?) { where("name LIKE ?", "%#{params[:name]}%")}.
order(published_at: :desc)
```
+
+Condition part of `exec_if` can be one of these:
+
+* `Proc`, which is called with self
+* `Symbol`, which is the name of the message of send
+* `String`, which is `eval`uated in context of self
+* `Object`, which is simply used to check truthyness
+
+See `examples` directory for usage.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.