karmi/tire — pull request #558 by barakcoh (2012-12-25 12:16:58+00:00)
Title: Persistence: Fix invalid casting of nil in casted collections

When using ```Tire::Model::Persistence``` with a casted collection, casting fails when the value is nil.

Suggested patch will always cast nil value to nil (i.e. do nothing)

**Example**

```ruby
class Job
def initialize(params); @attributes = HashWithIndifferentAccess.new(params); end
def method_missing(method_name, *arguments); @attributes[method_name]; end
def as_json(*); @attributes; end
end

class Company
include Tire::Model::Persistence

property :name, :analyzer => 'keyword'
property :jobs, :class => [Job]
end
```

```
1.9.3p194 :006 > Company.create name: 'foo', jobs: nil
NoMethodError: undefined method `new' for [Job]:Array
from /Users/barak/.rvm/gems/ruby-1.9.3-p194/gems/tire-0.5.2/lib/tire/model/persistence/attributes.rb:124:in `__cast_value'
from /Users/barak/.rvm/gems/ruby-1.9.3-p194/gems/tire-0.5.2/lib/tire/model/persistence/attributes.rb:110:in `block in __update_attributes'
from /Users/barak/.rvm/gems/ruby-1.9.3-p194/gems/tire-0.5.2/lib/tire/model/persistence/attributes.rb:110:in `each'
from /Users/barak/.rvm/gems/ruby-1.9.3-p194/gems/tire-0.5.2/lib/tire/model/persistence/attributes.rb:110:in `__update_attributes'
...
```