teaminsight/ns-options — pull request #43 by kellyredding (2012-05-18 16:27:36+00:00)
Title: Custom type class returned_value handling

### Honor options values responding to `returned_value`

There are times when it is nice to use a custom type class as a 'value handler'. Typically this is to use a class to sanitize and validate incoming values. You want to write a value and get the sanitized value of what is written back when reading that value. You may not care that the value is a custom class - you just want the value of what the class processed.

This change will allow developers to define a `returned_value` method on the type classes. If NsOptions sees that method it will call it and return its value when reading the option. Otherwise it will behave as normal.

### Added to NsOptions::Boolean

I went ahead and added this to the Boolean handler class. This is a great example of why you want something like this. You shouldn't have to fuddle with all the actual junk when dealing with booleans. I know I had previously committed changes that took out special boolean handling (f8f44ff0a7808544c4f40bf8c8400dfe0d9f7171) but I think this approach allows for a much more scalable way to support special return value handling. It doesn't rely on the Option class doing kind_of? checks for example.

### Tests

I added tests for this. I added a bunch of control tests when doing this. I wanted to make sure I wasn't breaking the normal option value behavior if the `returned_value` method wasn't specified. They may be too much - I'll let you decide and will modify if needed.