module Katapult::BinaryUtil
Public Instance Methods
ask(question)
click to toggle source
# File lib/katapult/support/binary_util.rb, line 43 def ask(question) pink(question, linefeed: false) gets.chomp end
create_rails_app(name)
click to toggle source
# 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)
click to toggle source
# File lib/katapult/support/binary_util.rb, line 66 def fail(message) puts "x #{message}" exit(1) end
git_commit(message, options = nil)
click to toggle source
# 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 <katapult@makandra.com>' #{ options }" end
job(do_something, done = 'Done.', &job)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
With clean Bundler env
# 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)
click to toggle source
# File lib/katapult/support/binary_util.rb, line 71 def snake_case(string) string.gsub(/([a-z])([A-Z])/,'\1_\2').downcase end