Class: Diggit::EntryWithRunnables
- Inherits:
-
Object
- Object
- Diggit::EntryWithRunnables
- Defined in:
- lib/dgit/entries.rb
Overview
Journal entry for elements that can launch runnables.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#canceled ⇒ Array<RunnableEntry>
readonly
The list of canceled runnables.
-
#performed ⇒ Array<RunnableEntry>
readonly
The list of performed runnables.
Instance Method Summary collapse
-
#clean(runnable_or_string) ⇒ void
Remove a runnable from all the entries.
-
#error? ⇒ Boolean
Error status of the element.
-
#has?(runnable_or_string, state = :all) ⇒ Boolean
Check if a runnable has been performed or canceled.
-
#initialize ⇒ EntryWithRunnables
constructor
A new instance of EntryWithRunnables.
Constructor Details
#initialize ⇒ EntryWithRunnables
43 44 45 46 |
# File 'lib/dgit/entries.rb', line 43 def initialize @performed = [] @canceled = [] end |
Instance Attribute Details
#canceled ⇒ Array<RunnableEntry> (readonly)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dgit/entries.rb', line 40 class EntryWithRunnables attr_reader :performed, :canceled def initialize @performed = [] @canceled = [] end # Error status of the element. # @return [Boolean] def error? !@canceled.empty? end # Check if a runnable has been performed or canceled. # @param runnable_or_string [Runnable, String] the runnable or the name of the runnable. # @param state [Symbol] the status of the runnable: `:performed`, `:canceled` or `:all`. # @return [Boolean] def has?(runnable_or_string, state = :all) name = retrieve_name(runnable_or_string) return @performed.count { |e| e.name == name } > 0 if state == :performed return @canceled.count { |e| e.name == name } > 0 if state == :canceled return (@performed + @canceled).count { |e| e.name == name } > 0 if state == :all end # Remove a runnable from all the entries. # @param runnable_or_string [Runnable, String] the runnable or the name of the runnable # @return [void] def clean(runnable_or_string) name = retrieve_name(runnable_or_string) @performed.delete_if { |e| e.name == name } @canceled.delete_if { |e| e.name == name } end private def retrieve_name(runnable_or_string) return runnable_or_string if runnable_or_string.is_a? String runnable_or_string.name end end |
#performed ⇒ Array<RunnableEntry> (readonly)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dgit/entries.rb', line 40 class EntryWithRunnables attr_reader :performed, :canceled def initialize @performed = [] @canceled = [] end # Error status of the element. # @return [Boolean] def error? !@canceled.empty? end # Check if a runnable has been performed or canceled. # @param runnable_or_string [Runnable, String] the runnable or the name of the runnable. # @param state [Symbol] the status of the runnable: `:performed`, `:canceled` or `:all`. # @return [Boolean] def has?(runnable_or_string, state = :all) name = retrieve_name(runnable_or_string) return @performed.count { |e| e.name == name } > 0 if state == :performed return @canceled.count { |e| e.name == name } > 0 if state == :canceled return (@performed + @canceled).count { |e| e.name == name } > 0 if state == :all end # Remove a runnable from all the entries. # @param runnable_or_string [Runnable, String] the runnable or the name of the runnable # @return [void] def clean(runnable_or_string) name = retrieve_name(runnable_or_string) @performed.delete_if { |e| e.name == name } @canceled.delete_if { |e| e.name == name } end private def retrieve_name(runnable_or_string) return runnable_or_string if runnable_or_string.is_a? String runnable_or_string.name end end |
Instance Method Details
#clean(runnable_or_string) ⇒ void
This method returns an undefined value.
Remove a runnable from all the entries.
68 69 70 71 72 |
# File 'lib/dgit/entries.rb', line 68 def clean(runnable_or_string) name = retrieve_name(runnable_or_string) @performed.delete_if { |e| e.name == name } @canceled.delete_if { |e| e.name == name } end |
#error? ⇒ Boolean
Error status of the element.
50 51 52 |
# File 'lib/dgit/entries.rb', line 50 def error? !@canceled.empty? end |
#has?(runnable_or_string, state = :all) ⇒ Boolean
Check if a runnable has been performed or canceled.
58 59 60 61 62 63 |
# File 'lib/dgit/entries.rb', line 58 def has?(runnable_or_string, state = :all) name = retrieve_name(runnable_or_string) return @performed.count { |e| e.name == name } > 0 if state == :performed return @canceled.count { |e| e.name == name } > 0 if state == :canceled return (@performed + @canceled).count { |e| e.name == name } > 0 if state == :all end |