Class: Agentilda::Status
- Inherits:
-
Data
- Object
- Data
- Agentilda::Status
- 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
-
#emoji ⇒ String
readonly
As it appears in the folder name.
-
#invariant ⇒ Proc?
readonly
(subject) -> String | nil— the reason it does not hold. -
#key ⇒ Symbol
readonly
Machine-facing name, e.g.
-
#label ⇒ String
readonly
The human words.
-
#note ⇒ String
readonly
One-line meaning, for tables and generated docs.
-
#requires ⇒ Array<String>
readonly
Files this state cannot be honest without.
Instance Method Summary collapse
- #satisfied_by?(subject) ⇒ Boolean
-
#terminal? ⇒ Boolean
Whether nothing may follow this state.
-
#to_s ⇒ String
Emoji and words, as the tables print it.
-
#violation(subject) ⇒ String?
Why this state is not justified, nil when it is.
Instance Attribute Details
#emoji ⇒ String (readonly)
Returns 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 |
#invariant ⇒ Proc? (readonly)
Returns (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 |
#key ⇒ Symbol (readonly)
Returns 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 |
#label ⇒ String (readonly)
Returns 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 |
#note ⇒ String (readonly)
Returns 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 |
#requires ⇒ Array<String> (readonly)
Returns 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
27 |
# File 'lib/agentilda/status.rb', line 27 def satisfied_by?(subject) = violation(subject).nil? |
#terminal? ⇒ Boolean
Returns whether nothing may follow this state.
39 |
# File 'lib/agentilda/status.rb', line 39 def terminal? = StateMachine.outbound(key).empty? |
#to_s ⇒ String
Returns 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.
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 |