Module: SoulPoints::Helpers

Included in:
Client
Defined in:
lib/soul_points/helpers.rb

Instance Method Summary collapse

Instance Method Details

#askObject



78
79
80
# File 'lib/soul_points/helpers.rb', line 78

def ask
  gets.strip
end

#confirm(message = "Are you sure you wish to continue? (y/n)?") ⇒ Object



38
39
40
41
# File 'lib/soul_points/helpers.rb', line 38

def confirm(message="Are you sure you wish to continue? (y/n)?")
  display("#{message} ", false)
  ask.downcase == 'y'
end

#confirm_command(app = app) ⇒ Object

Raises:

  • (SoulPoints::Command::CommandFailed)


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
# File 'lib/soul_points/helpers.rb', line 43

def confirm_command(app = app)
  if extract_option('--force')
    display("Warning: The --force switch is deprecated, and will be removed in a future release. Use --confirm #{app} instead.")
    return true
  end

  raise(SoulPoints::Command::CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") unless app

  confirmed_app = extract_option('--confirm', false)
  if confirmed_app
    unless confirmed_app == app
      raise(SoulPoints::Command::CommandFailed, "Confirmed app #{confirmed_app} did not match the selected app #{app}.")
    end
    return true
  else
    display ""
    display " !    WARNING: Potentially Destructive Action"
    display " !    This command will affect the app: #{app}"
    display " !    To proceed, type \"#{app}\" or re-run this command with --confirm #{app}"
    display ""
    display "> ", false
    if ask.downcase != app
      display " !    Input did not match #{app}. Aborted."
      false
    else
      true
    end
  end
end

#deprecate(version) ⇒ Object



28
29
30
31
# File 'lib/soul_points/helpers.rb', line 28

def deprecate(version)
  display "!!! DEPRECATION WARNING: This command will be removed in version #{version}"
  display ""
end

#display(msg, newline = true) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/soul_points/helpers.rb', line 15

def display(msg, newline=true)
  if newline
    puts(msg)
  else
    print(msg)
    STDOUT.flush
  end
end

#error(msg) ⇒ Object



33
34
35
36
# File 'lib/soul_points/helpers.rb', line 33

def error(msg)
  STDERR.puts(msg)
  exit 1
end

#format_date(date) ⇒ Object



73
74
75
76
# File 'lib/soul_points/helpers.rb', line 73

def format_date(date)
  date = Time.parse(date) if date.is_a?(String)
  date.strftime("%Y-%m-%d %H:%M %Z")
end

#home_directoryObject



3
4
5
# File 'lib/soul_points/helpers.rb', line 3

def home_directory
  running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
end

#redisplay(line, line_break = false) ⇒ Object



24
25
26
# File 'lib/soul_points/helpers.rb', line 24

def redisplay(line, line_break = false)
  display("\r\e[0K#{line}", line_break)
end

#retry_on_exception(*exceptions) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/soul_points/helpers.rb', line 90

def retry_on_exception(*exceptions)
  retry_count = 0
  begin
    yield
  rescue *exceptions => ex
    raise ex if retry_count >= 3
    sleep 3
    retry_count += 1
    retry
  end
end

#run_command(command, args = []) ⇒ Object



86
87
88
# File 'lib/soul_points/helpers.rb', line 86

def run_command(command, args=[])
  SoulPoints::Command.run_internal(command, args)
end

#running_on_a_mac?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/soul_points/helpers.rb', line 11

def running_on_a_mac?
  RUBY_PLATFORM =~ /-darwin\d/
end

#running_on_windows?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/soul_points/helpers.rb', line 7

def running_on_windows?
  RUBY_PLATFORM =~ /mswin32|mingw32/
end

#shell(cmd) ⇒ Object



82
83
84
# File 'lib/soul_points/helpers.rb', line 82

def shell(cmd)
  FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
end