Module: Katapult::BinaryUtil

Extended by:
BinaryUtil
Included in:
BinaryUtil
Defined in:
lib/katapult/support/binary_util.rb

Instance Method Summary collapse

Instance Method Details

#ask(question) ⇒ Object



43
44
45
46
# File 'lib/katapult/support/binary_util.rb', line 43

def ask(question)
  pink(question, linefeed: false)
  gets.chomp
end

#create_rails_app(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/katapult/support/binary_util.rb', line 19

def create_rails_app(name)
  version = Katapult::RAILS_VERSION
  options = %w[
    --database postgresql
    --webpack

    --skip-test
    --skip-system-test
    --skip-turbolinks
  ]

  success = run "rails _#{version}_ new #{name} " + options.join(' ')
  success or fail 'Failed to create Rails app'
end

#fail(message) ⇒ Object



66
67
68
69
# File 'lib/katapult/support/binary_util.rb', line 66

def fail(message)
  puts "x #{message}"
  exit(1)
end

#git_commit(message, options = nil) ⇒ Object



14
15
16
17
# File 'lib/katapult/support/binary_util.rb', line 14

def git_commit(message, options = nil)
  message.gsub! /'/, "" # remove single quotes
  system "git add --all; git commit -m '#{ message }' --author='katapult <[email protected]>' #{ options }"
end

#job(do_something, done = 'Done.', &job) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/katapult/support/binary_util.rb', line 54

def job(do_something, done = 'Done.', &job)
  pink "About to #{do_something}. [C]ontinue, [s]kip or [e]xit?"

  case $stdin.getch
  when 's' then puts('Skipped.')
  when 'e' then fail('Cancelled.')
  else
    job.call
    puts done
  end
end

#pink(*args, linefeed: true) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/katapult/support/binary_util.rb', line 34

def pink(*args, linefeed: true)
  message = "> #{ args.join ' ' }"
  message.prepend($/) if linefeed
  message << (linefeed ? $/ : ' ')

  pink_message = "\e[35m#{ message }\e[0m"
  print pink_message
end

#run(command) ⇒ Object

With clean Bundler env



49
50
51
52
# File 'lib/katapult/support/binary_util.rb', line 49

def run(command)
  success = Bundler.with_clean_env { system command }
  success or fail 'Something went wrong'
end

#snake_case(string) ⇒ Object



71
72
73
# File 'lib/katapult/support/binary_util.rb', line 71

def snake_case(string)
  string.gsub(/([a-z])([A-Z])/,'\1_\2').downcase
end