Sha256: 3fae51237dcb11717429b2f9638b1d0a3be6de195a114bda858d7dcb7b407d84
Contents?: true
Size: 723 Bytes
Versions: 1
Compression:
Stored size: 723 Bytes
Contents
require "securerandom" module Basket class Element class InvalidElement < StandardError; end attr_reader :data, :id def self.from_queue(element) if element.is_a?(Element) element elsif element.is_a?(Hash) new(element["data"], element["id"]) else raise InvalidElement, "element must be a hash or a Basket::Element" end end def initialize(data, id = SecureRandom.uuid) raise InvalidElement, "both data and id must be present" unless data && id @data = data @id = id end def to_h {data: data, id: id} end def to_json(*) to_h.to_json end def ==(other) to_h == other.to_h end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
basket-0.0.7 | lib/basket/element.rb |