rails/rails — pull request #14461 by jalkoby (2014-03-23 23:24:34+00:00)
Title: Improve store attributes feature

There are 2 changes in store attributes feature:

- cast a value of a serialized attribute to a specified type
```ruby
class User < ActiveRecord::Base
store :profile
store_accessor :profile, :name, :age, :use_gravatar

def age=(value)
value = ActiveRecord::ConnectionAdapters::Column.value_to_integer(value)
super
end

def use_gravatar=(value)
value = ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
super
end
end

# replaced by

class User < ActiveRecord::Base
store :profile
store_accessor :profile, :name, :age => :integer, :use_gravatar => :boolean
end
```

- default value
```ruby
class Car < ActiveRecord::Base
store :settings
store_accessor :settings, :color

def color
super || 'red'
end
end

# replaced by
class Car < ActiveRecord::Base
store :settings
store_accessor :settings, :color => { :default => 'red' }
end
```

2 features together

```ruby
class User < ActiveRecord::Base
store :profile
store_accessor :profile, :age => { :type => :integer, :default => 18 }
end
```

Also, `read_stored_attribute` and `write_stored_attribute` were changed. They don't need to specify store_attribute if it was specified in `store_accessor`.