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)


90
91
92
93
94
95
# File 'lib/webhookdb/service/entities.rb', line 90

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