Class: Diggit::EntryWithRunnables

Inherits:
Object
  • Object
show all
Defined in:
lib/dgit/entries.rb

Overview

Journal entry for elements that can launch runnables.

Direct Known Subclasses

SourceEntry, WorkspaceEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntryWithRunnables

Returns a new instance of EntryWithRunnables.



43
44
45
46
# File 'lib/dgit/entries.rb', line 43

def initialize
  @performed = []
  @canceled = []
end

Instance Attribute Details

#canceledArray<RunnableEntry> (readonly)

Returns the list of canceled runnables.

Returns:



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

#performedArray<RunnableEntry> (readonly)

Returns the list of performed runnables.

Returns:



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.

Parameters:

  • runnable_or_string (Runnable, String)

    the runnable or the name of the runnable



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.

Returns:

  • (Boolean)


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.

Parameters:

  • runnable_or_string (Runnable, String)

    the runnable or the name of the runnable.

  • state (Symbol) (defaults to: :all)

    the status of the runnable: :performed, :canceled or :all.

Returns:

  • (Boolean)


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