Module: Katapult::BinaryUtil
Instance Method Summary collapse
- #ask(question) ⇒ Object
- #create_rails_app(name) ⇒ Object
- #fail(message) ⇒ Object
- #git_commit(message, options = nil) ⇒ Object
- #job(do_something, done = 'Done.', &job) ⇒ Object
- #pink(*args, linefeed: true) ⇒ Object
-
#run(command) ⇒ Object
With clean Bundler env.
- #snake_case(string) ⇒ Object
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 = %w[ --database postgresql --webpack --skip-test --skip-system-test --skip-turbolinks ] success = run "rails _#{version}_ new #{name} " + .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() puts "x #{}" 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(, = nil) .gsub! /'/, "" # remove single quotes system "git add --all; git commit -m '#{ }' --author='katapult <[email protected]>' #{ }" 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) = "> #{ args.join ' ' }" .prepend($/) if linefeed << (linefeed ? $/ : ' ') = "\e[35m#{ }\e[0m" print 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 |