Class: Coat::Mend

Inherits:
Struct
  • Object
show all
Defined in:
lib/coat/seam.rb

Overview

A person's word that a seam is settled. coat can see that two agents laid patches over the same ground; it cannot see which one was right. Only a human closes that, so mending is the one thing in the ledger a person does rather than a tool.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#byObject

Returns the value of attribute by

Returns:

  • (Object)

    the current value of by



10
11
12
# File 'lib/coat/seam.rb', line 10

def by
  @by
end

#noteObject

Returns the value of attribute note

Returns:

  • (Object)

    the current value of note



10
11
12
# File 'lib/coat/seam.rb', line 10

def note
  @note
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



10
11
12
# File 'lib/coat/seam.rb', line 10

def path
  @path
end

#tsObject

Returns the value of attribute ts

Returns:

  • (Object)

    the current value of ts



10
11
12
# File 'lib/coat/seam.rb', line 10

def ts
  @ts
end

Class Method Details

.all(entries) ⇒ Object

Keyed by path, latest word winning: mending the same seam twice is a correction, not a second seam.



17
18
19
20
# File 'lib/coat/seam.rb', line 17

def self.all(entries)
  entries.select { |entry| entry["event"] == MEND_EVENT }
         .to_h { |entry| [entry["path"], from(entry)] }
end

.entry(path:, by:, note:, at: Time.now) ⇒ Object

The ledger line for a mend. Written here so the one place that knows what a mend looks like is the thing that reads them back.



24
25
26
27
28
29
# File 'lib/coat/seam.rb', line 24

def self.entry(path:, by:, note:, at: Time.now)
  {
    "ts" => at.getutc.strftime("%Y-%m-%dT%H:%M:%SZ"), "event" => MEND_EVENT,
    "path" => path, "by" => by, "note" => note
  }
end

.from(entry) ⇒ Object



11
12
13
# File 'lib/coat/seam.rb', line 11

def self.from(entry)
  new(**entry.slice(*members.map(&:to_s)).transform_keys(&:to_sym))
end