def save
      indices = {}
      model.indices.each do |field|
        next unless (value = send(field))
        indices[field] = Array(value).map(&:to_s)
      end

      uniques = {}
      model.uniques.each do |field|
        next unless (value = send(field))
        uniques[field] = value.to_s
      end

      features = {
        "name" => model.name
      }

      if defined?(@id)
        features["id"] = @id
      end

      @id = script(LUA_SAVE, 0,
        features.to_json,
        _sanitized_attributes.to_json,
        indices.to_json,
        uniques.to_json
      )

      return self
    end
def save
      indices = {}
      model.indices.each do |field|
        next unless (value = send(field))
        indices[field] = Array(value).map(&:to_s)
      end

      uniques = {}
      model.uniques.each do |field|
        next unless (value = send(field))
        uniques[field] = value.to_s
      end

      features = {
        "name" => model.name
      }

      if defined?(@id)
        features["id"] = @id
      end

      @id = script(LUA_SAVE, 0,
        features.to_json,
        _sanitized_attributes.to_json,
        indices.to_json,
        uniques.to_json
      )

      return self
    end
Persist the model attributes and update indices and unique
 indices. The `counter`s and `set`s are not touched during save.

 Example:

   class User < Ohm::Model
     attribute :name
   end

   u = User.new(:name => "John").save
   u.kind_of?(User)
   # => true