A module to mixin Aquasync Model requirements.
require 'aquasync_model'
class Book
include Aquasync::Base
field :name
end
Then it automatically mixin fields, callbacks, validators to satisfy Aquasync Model requirement.
#before_save
ust are set when saved
gid should be lowercase
validation
does not allow nil for :gid
does not allow nil for :deviceToken
does not allow nil for :localTimestamp
allows lowercase UUID values for :gid
does not allow not-UUID value for :gid
allows lowercase UUID values for :deviceToken
does not allow not-UUID value for :deviceToken
#to_h
does not include _id
does not include ust
# should be UNIX timestamp
# @example 1406697904
field :ust, type: Integer
# should be UNIX timestamp
# @example 1406697904
field :localTimestamp, type: Integer
# should be UUIDv1
# @example 550e8400-e29b-41d4-a716-446655440000
field :gid, type: String
# should be UUIDv1
# @example 550e8400-e29b-41d4-a716-446655440000
field :deviceToken, type: String
# for paranoid deletion
# @example false
field :isDeleted, type: Boolean
before_validation do
downcase_gid
downcase_device_token
set_ust
end
validates_presence_of :gid
validates_format_of :gid, with: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
validates_presence_of :ust
validates_presence_of :deviceToken
validates_format_of :deviceToken, with: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
validates_presence_of :localTimestamp
def aq_deltas(ust)
where(:ust.gt => ust)
end
def aq_commit_deltas(deltas)
deltas.each {|delta| commit_delta(delta) }
end
def to_h
serializable_hash.delete_if {|key| key == "_id" or key == "ust"}
end