Introduce an Attribute object to handle the type casting dance

Depends on #15429 and includes the changes from that PR as well. There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are:

- Remove all knowledge of type casting from the columns, beyond a
  reference to the cast_type
- Move type_cast_for_database to these objects
- Potentially make them mutable, introduce a state machine, and have
  dirty checking handled here as well
- Move `attribute`, `decorate_attribute`, and anything else that
  modifies types to mess with this object, not the columns hash
- Introduce a collection object to manage these, reduce allocations, and
  not require serializing the types
Yeah I don't think we'd gain much there
On Jun 9, 2014 9:08 PM, "Eugene Gilburg" <notifications@github.com> wrote:

> In activerecord/lib/active_record/attribute.rb:
>
> > @@ -0,0 +1,61 @@
> > +module ActiveRecord
> > +  class Attribute # :nodoc:
> > +    class << self
> > +      def from_database(value, type)
> > +        FromDatabase.new(value, type)
> > +      end
> > +
> > +      def from_user(value, type)
> > +        FromUser.new(value, type)
> > +      end
> > +    end
> > +
> > +    attr_reader :value_before_type_cast, :type
> > +
> > +    # This method should not be called directly.
>
> right. you could declare private_class_method :new then. not that it
> matters a huge lot in this case, being already a private class to begin
> with.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/rails/rails/pull/15593/files#r13575874>.
>