title: How to handle mongoid custom type dirty tracking?
body: <p>I've got the following custom field type that allows me to save a GeoJSON LineString while treating the field like an array of points:</p>
  
  <pre><code>class GeoLineString
  
    attr_reader :coordinates
  
    def initialize(array)
      @coordinates = array
    end
  
    # Converts an object of this instance into a database friendly value.
    def mongoize
      {
          "type" =&gt; "LineString",
          "coordinates" =&gt; @coordinates
      }
    end
  
    def as_json(options={})
      mongoize
    end
  
    class &lt;&lt; self
  
      # Get the object as it was stored in the database, and instantiate
      # this custom class from it.
      def demongoize(object)
        return self.new(object["coordinates"]) if object.is_a?(Hash)
      end
  
      # Takes any possible object and converts it to how it would be
      # stored in the database.
      def mongoize(object)
        case object
          when GeoLineString then object.mongoize
          when Array then GeoLineString.new(object).mongoize
          else object
        end
      end
  
      # Converts the object that was supplied to a criteria and converts it
      # into a database friendly form.
      def evolve(object)
        case object
          when GeoLineString then object.mongoize
          else object
        end
      end
    end
  end  
  </code></pre>
  
  <p>Which i use as follows in my model:</p>
  
  <pre><code>class Track
    include Mongoid::Document
    include Mongoid::Timestamps
  
    field :name, type: String
    field :coordinates, type: ::GeoLineString
    index({ coordinates: "2dsphere" }, { min: -200, max: 200 })
  end
  </code></pre>
  
  <p>This works as expected but when i want to change the coordinates inside of the GeoLineString field mongoid does not recognize the field "coordinates" as dirty an thus does not update it in the database. Example:</p>
  
  <pre><code>t=Track.last
  =&gt; #&lt;Track _id: 568a70e6859c862ee1000000, created_at: 2016-01-04 13:17:40 UTC, updated_at: 2016-01-04 13:17:40 UTC, name: nil, coordinates: {"type"=&gt;"LineString", "coordinates"=&gt;[[1, 2], [2, 2]]}&gt;
  
  t.coordinates.coordinates.push([3,3])
  
  t
  =&gt; #&lt;Track _id: 568a70e6859c862ee1000000, created_at: 2016-01-04 13:17:40 UTC, updated_at: 2016-01-04 13:17:40 UTC, name: nil, coordinates: {"type"=&gt;"LineString", "coordinates"=&gt;[[1, 2], [2, 2], [3, 3]]}&gt;
  
  t.changed?
  =&gt; false
  </code></pre>
  
  <p>How can i get mongoid to recognize that the value has changed?</p>