Class: Mistri::Workspace::Snapshot

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, revision:) ⇒ Snapshot

Returns a new instance of Snapshot.

Raises:

  • (ArgumentError)


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

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



16
17
18
# File 'lib/mistri/workspace.rb', line 16

def content
  @content
end

#revisionObject (readonly)

Returns the value of attribute revision

Returns:

  • (Object)

    the current value of revision



16
17
18
# File 'lib/mistri/workspace.rb', line 16

def revision
  @revision
end

Class Method Details

.for(content) ⇒ Object

Raises:

  • (ArgumentError)


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