Class: Agentilda::Status

Inherits:
Data
  • Object
show all
Defined in:
lib/agentilda/status.rb

Overview

A folder's state: what it means, which files it cannot be honest without, and the rule that decides whether the folder may legitimately claim it.

invariant is asked in both directions. StateMachine asks it of a destination before moving there; resync and check ask it of the current state, to catch folders whose name has drifted from their contents. One definition, so the two can never disagree about what a state means.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emojiString (readonly)

Returns as it appears in the folder name.

Returns:

  • (String)

    as it appears in the folder name



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

#invariantProc? (readonly)

Returns (subject) -> String | nil — the reason it does not hold.

Returns:

  • (Proc, nil)

    (subject) -> String | nil — the reason it does not hold



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

#keySymbol (readonly)

Returns machine-facing name, e.g. :product_blocked.

Returns:

  • (Symbol)

    machine-facing name, e.g. :product_blocked



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

#labelString (readonly)

Returns the human words.

Returns:

  • (String)

    the human words



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

#noteString (readonly)

Returns one-line meaning, for tables and generated docs.

Returns:

  • (String)

    one-line meaning, for tables and generated docs



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

#requiresArray<String> (readonly)

Returns files this state cannot be honest without.

Returns:

  • (Array<String>)

    files this state cannot be honest without



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agentilda/status.rb', line 24

Status = Data.define(:key, :emoji, :label, :requires, :note, :invariant) do
  # @param subject [#file?, #read, #pull_requests]
  # @return [Boolean]
  def satisfied_by?(subject) = violation(subject).nil?

  # @param subject [#file?, #read, #pull_requests]
  # @return [String, nil] why this state is not justified, nil when it is
  def violation(subject)
    missing = requires.reject { |f| subject.file?(f) }
    return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

    invariant&.call(subject)
  end

  # @return [Boolean] whether nothing may follow this state
  def terminal? = StateMachine.outbound(key).empty?

  # @return [String] emoji and words, as the tables print it
  def to_s = "#{emoji} #{label}"
end

Instance Method Details

#satisfied_by?(subject) ⇒ Boolean

Parameters:

  • subject (#file?, #read, #pull_requests)

Returns:

  • (Boolean)


27
# File 'lib/agentilda/status.rb', line 27

def satisfied_by?(subject) = violation(subject).nil?

#terminal?Boolean

Returns whether nothing may follow this state.

Returns:

  • (Boolean)

    whether nothing may follow this state



39
# File 'lib/agentilda/status.rb', line 39

def terminal? = StateMachine.outbound(key).empty?

#to_sString

Returns emoji and words, as the tables print it.

Returns:

  • (String)

    emoji and words, as the tables print it



42
# File 'lib/agentilda/status.rb', line 42

def to_s = "#{emoji} #{label}"

#violation(subject) ⇒ String?

Returns why this state is not justified, nil when it is.

Parameters:

  • subject (#file?, #read, #pull_requests)

Returns:

  • (String, nil)

    why this state is not justified, nil when it is



31
32
33
34
35
36
# File 'lib/agentilda/status.rb', line 31

def violation(subject)
  missing = requires.reject { |f| subject.file?(f) }
  return "#{label} requires #{missing.map { |f| "`#{f}`" }.join(" and ")}" unless missing.empty?

  invariant&.call(subject)
end