Class: Mistri::Workspace::Snapshot
- Inherits:
-
Data
- Object
- Data
- Mistri::Workspace::Snapshot
- Defined in:
- lib/mistri/workspace.rb
Overview
One immutable document representation and the opaque token that binds a later conditional write to these exact bytes.
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content:, revision:) ⇒ Snapshot
constructor
A new instance of Snapshot.
Constructor Details
#initialize(content:, revision:) ⇒ Snapshot
Returns a new instance of Snapshot.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mistri/workspace.rb', line 17 def initialize(content:, revision:) raise ArgumentError, "snapshot content must be a String" unless content.is_a?(String) raise ArgumentError, "snapshot revision must be a String" unless revision.is_a?(String) owned_content = String.new(content) owned_revision = String.new(revision) unless !owned_revision.empty? && owned_revision.bytesize <= MAX_REVISION_BYTES raise ArgumentError, "snapshot revision must be 1-#{MAX_REVISION_BYTES} bytes" end super(content: owned_content.freeze, revision: owned_revision.freeze) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content
16 17 18 |
# File 'lib/mistri/workspace.rb', line 16 def content @content end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision
16 17 18 |
# File 'lib/mistri/workspace.rb', line 16 def revision @revision end |
Class Method Details
.for(content) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mistri/workspace.rb', line 31 def self.for(content) raise ArgumentError, "snapshot content must be a String" unless content.is_a?(String) owned = String.new(content) new(content: owned, revision: Digest::SHA256.hexdigest(owned.b)) end |