Module: Utilities
- Included in:
- Release, ReleaseModel, ReleaseProcess
- Defined in:
- lib/release/util/utilities.rb
Instance Method Summary collapse
- #ask(question, suggestion) ⇒ Object
- #echo_with_color(text, color) ⇒ Object
- #help_info(text) ⇒ Object
- #next_snapshot(version) ⇒ Object
- #read_file(file_name) ⇒ Object
- #right_padding(string, length) ⇒ Object
- #terminate ⇒ Object
- #verify_pattern(value, regex) ⇒ Object
- #verify_pattern_terminate(value, regex) ⇒ Object
- #wait_or_do(message) ⇒ Object
- #write_file(file_name, file_content) ⇒ Object
Instance Method Details
#ask(question, suggestion) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/release/util/utilities.rb', line 31 def ask(question, suggestion) puts echo_with_color "#{question} #{suggestion} : ", 'green' $stdout.flush answer = gets.chomp unless answer == '' return answer end echo_with_color suggestion, 'yellow' suggestion end |
#echo_with_color(text, color) ⇒ Object
6 7 8 |
# File 'lib/release/util/utilities.rb', line 6 def echo_with_color(text, color) print text.send("#{color}") end |
#help_info(text) ⇒ Object
14 15 16 |
# File 'lib/release/util/utilities.rb', line 14 def help_info(text) echo_with_color text, 'yellow' end |
#next_snapshot(version) ⇒ Object
63 64 65 66 |
# File 'lib/release/util/utilities.rb', line 63 def next_snapshot(version) parts = $version.match(version).captures "#{parts[0]}#{Integer(parts[1])+1}-SNAPSHOT" end |
#read_file(file_name) ⇒ Object
53 54 55 |
# File 'lib/release/util/utilities.rb', line 53 def read_file(file_name) File.open(file_name).read end |
#right_padding(string, length) ⇒ Object
68 69 70 |
# File 'lib/release/util/utilities.rb', line 68 def right_padding(string,length) (string + ' ' * length)[0,length] end |
#terminate ⇒ Object
10 11 12 |
# File 'lib/release/util/utilities.rb', line 10 def terminate abort 'Program terminated' end |
#verify_pattern(value, regex) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/release/util/utilities.rb', line 24 def verify_pattern(value, regex) unless regex.match(value) echo_with_color "#{value} must match #{regex}", 'red' yield end end |
#verify_pattern_terminate(value, regex) ⇒ Object
18 19 20 21 22 |
# File 'lib/release/util/utilities.rb', line 18 def verify_pattern_terminate(value, regex) verify_pattern value, regex do terminate end end |
#wait_or_do(message) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/release/util/utilities.rb', line 46 def wait_or_do() echo_with_color , 'red' unless (ask 'Continue?', 'y') == 'y' yield end end |
#write_file(file_name, file_content) ⇒ Object
57 58 59 60 61 |
# File 'lib/release/util/utilities.rb', line 57 def write_file(file_name, file_content) File.open(file_name, 'w') do |file| file.write(file_content) end end |