Module: NattyUI::WithStatus

Included in:
ProgressHelper, Section, Task
Defined in:
lib/natty-ui/element.rb

Overview

Methods for elements with status like ProgressHelper, Section, Task.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active?true, false (readonly)

Returns whether the element is still active.

Returns:

  • (true, false)

    whether the element is still active



57
# File 'lib/natty-ui/element.rb', line 57

def active? = @status.nil?

#closed?true, false (readonly)

Returns whether the element is completed.

Returns:

  • (true, false)

    whether the element is completed



61
# File 'lib/natty-ui/element.rb', line 61

def closed? = !active?

#failed?true, false (readonly)

Returns whether the element is completed with failure.

Returns:

  • (true, false)

    whether the element is completed with failure



69
# File 'lib/natty-ui/element.rb', line 69

def failed? = @state == :failed

#statusSymbol? (readonly)

Returns element's current status.

Returns:

  • (Symbol, nil)

    element's current status



53
54
55
# File 'lib/natty-ui/element.rb', line 53

def status
  @status
end

Instance Method Details

#failed(*text) {|failed| ... } ⇒ Element

Close the element with a failure.

Parameters:

  • text (#to_s)

    optional message

Yields:

  • optionally, when block is given

Yield Parameters:

Returns:



90
91
92
93
94
95
96
97
# File 'lib/natty-ui/element.rb', line 90

def failed(*text, &block)
  return self if @state
  _failed
  @state = :failed
  text = [@title] if text.empty? && @title
  @parent.failed(*text, &block)
  self
end

#ok(*text) ⇒ Element Also known as: done

Close the element.

Parameters:

  • text (#to_s)

    optional message

Returns:



75
76
77
78
79
80
81
# File 'lib/natty-ui/element.rb', line 75

def ok(*text)
  return self if @state
  text = [@title] if text.empty? && @title
  _done(text)
  @state = :ok
  self
end

#ok?true, false

Returns whether the element is completed.

Returns:

  • (true, false)

    whether the element is completed



65
# File 'lib/natty-ui/element.rb', line 65

def ok? = @state == :ok