Module: Webhookdb::Service::Entities::EtaggedMixin

Defined in:
lib/webhookdb/service/entities.rb

Overview

Add an ‘etag’ field to the rendered entity. This should only be used on the root entity, and entities with etags should not be nested. Usage:

class DashboardEntity < BaseEntity
  prepend Webhookdb::Service::Entities::EtaggedMixin
  expose :my_field
end

Instance Method Summary collapse

Instance Method Details

#to_jsonObject

Raises:

  • (TypeError)


86
87
88
89
90
91
# File 'lib/webhookdb/service/entities.rb', line 86

def to_json(*)
  serialized = super
  raise TypeError, "EtaggedMixin can only be used for object entities" unless serialized[-1] == "}"
  etag = Digest::MD5.hexdigest(Webhookdb::COMMIT.to_s + serialized)
  return serialized[...-1] + ",\"etag\":\"#{etag}\"}"
end