Module: IamsellekClHelper
- Defined in:
- lib/iamsellek_cl_helper.rb,
lib/iamsellek_cl_helper/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #bash(directory, command) ⇒ Object
- #delete_arguments(arguments, number_to_delete) ⇒ Object
- #double_space ⇒ Object
- #lines_pretty_print(string) ⇒ Object
-
#restore_settings(gem_name, version) ⇒ Object
Attempt to restore settings from previous version.
- #second_argument_missing?(arguments) ⇒ Boolean
- #single_space ⇒ Object
- #surround_by_double_space(string) ⇒ Object
Instance Method Details
#bash(directory, command) ⇒ Object
54 55 56 57 58 |
# File 'lib/iamsellek_cl_helper.rb', line 54 def bash(directory, command) # Dir.chdir ensures all bash commands are being run from the correct # directory. Dir.chdir(directory) { system "#{command}" } end |
#delete_arguments(arguments, number_to_delete) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/iamsellek_cl_helper.rb', line 47 def delete_arguments(arguments, number_to_delete) (1..number_to_delete).each do # Deleting the first one each time because the array shifts left when one is deleted. arguments.delete_at(0) end end |
#double_space ⇒ Object
70 71 72 |
# File 'lib/iamsellek_cl_helper.rb', line 70 def double_space puts "\n\n" end |
#lines_pretty_print(string) ⇒ Object
60 61 62 63 64 |
# File 'lib/iamsellek_cl_helper.rb', line 60 def lines_pretty_print(string) lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/) lines.each { |line| puts line } end |
#restore_settings(gem_name, version) ⇒ Object
Attempt to restore settings from previous version.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/iamsellek_cl_helper.rb', line 3 def restore_settings(gem_name, version) lines_pretty_print "I see that you have a previous #{gem_name} installation on this machine." lines_pretty_print Rainbow('Would you like to restore its settings?').yellow answered = false until answered answer = STDIN.gets.strip! single_space if answer == 'yes' || answer == 'y' || answer == 'no' || answer == 'n' answered = true else lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow end end return if answer == 'no' || answer == 'n' lines_pretty_print 'One moment, please.' single_space all_gems = Dir.glob("#{@app_directory.chomp("/#{gem_name}-#{version}")}/#{gem_name}*") # glob orders things in the array alphabetically, so the second-to-last one in the array is the # most recent version that is not the current version. previous_config_file = "#{all_gems[-2]}/lib/config.yaml" config = YAML.load_file(previous_config_file) new_config_file = File.open("#{@app_directory}/lib/config.yaml", 'w') YAML.dump(config, new_config_file) new_config_file.close lines_pretty_print 'Done! Please run me again when you\'re ready.' abort end |
#second_argument_missing?(arguments) ⇒ Boolean
43 44 45 |
# File 'lib/iamsellek_cl_helper.rb', line 43 def second_argument_missing?(arguments) arguments[1].nil? || arguments[1] == '' end |
#single_space ⇒ Object
66 67 68 |
# File 'lib/iamsellek_cl_helper.rb', line 66 def single_space puts '' end |
#surround_by_double_space(string) ⇒ Object
74 75 76 77 78 |
# File 'lib/iamsellek_cl_helper.rb', line 74 def surround_by_double_space(string) double_space lines_pretty_print(string) double_space end |