Class: TempestTime::Command

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tempest_time/command.rb

Instance Method Summary collapse

Instance Method Details

#commandObject



18
19
20
21
# File 'lib/tempest_time/command.rb', line 18

def command
  require 'tty-command'
  TTY::Command.new
end

#executeObject

Raises:

  • (NotImplementedError)


11
12
13
14
15
16
# File 'lib/tempest_time/command.rb', line 11

def execute(*)
  raise(
      NotImplementedError,
      "#{self.class}##{__method__} must be implemented"
  )
end

#pastel(**options) ⇒ Object



23
24
25
26
# File 'lib/tempest_time/command.rb', line 23

def pastel(**options)
  require 'pastel'
  Pastel.new(options)
end

#prompt(**options) ⇒ Object



28
29
30
31
# File 'lib/tempest_time/command.rb', line 28

def prompt(**options)
  require 'tty-prompt'
  TTY::Prompt.new(options)
end

#spinnerObject



33
34
35
36
# File 'lib/tempest_time/command.rb', line 33

def spinner
  require 'tty-spinner'
  TTY::Spinner
end

#tableObject



38
39
40
41
# File 'lib/tempest_time/command.rb', line 38

def table
  require 'tty-table'
  TTY::Table
end

#with_spinner(message, format = :pong) {|s| ... } ⇒ Object

Yields:

  • (s)


43
44
45
46
47
# File 'lib/tempest_time/command.rb', line 43

def with_spinner(message, format = :pong)
  s = spinner.new(":spinner #{message}", format: format)
  s.auto_spin
  yield(s)
end

#with_success_fail_spinner(message, format = :spin_3) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/tempest_time/command.rb', line 49

def with_success_fail_spinner(message, format = :spin_3)
  s = spinner.new(":spinner #{message}", format: format)
  s.auto_spin
  response = yield
  if response.success?
    s.success(pastel.green(response.message))
  else
    s.error(pastel.red(response.message))
  end
end