Module: Utils
- Included in:
- ChangelogBuilder, Continuous4r, DcovBuilder, FlayBuilder, FlogBuilder, RcovBuilder, RdocBuilder, ReekBuilder, RoodiBuilder, SaikuroBuilder, StatsBuilder, TestsBuilder, XdocletBuilder, ZentestBuilder
- Defined in:
- lib/utils.rb
Overview
Module de fonctions utilitaires necessaire a la construction
Class Method Summary collapse
-
.build_name ⇒ Object
Méthode qui permet de récupérerle numéro de build courant dans le SCM.
-
.erb_run(page, is_a_task = true) ⇒ Object
Methode qui permet de construire une page avec eruby, et de lever une exception au besoin.
-
.flog_caracteristics(flog_score) ⇒ Object
Méthode qui permet de typer une cellule de table HTML en fonction d’un score flog.
-
.flog_score_to_css_style(flog_score) ⇒ Object
Methode qui permet de convertir un score flog en couleur css/html de titre.
-
.percent_to_css_style(percent) ⇒ Object
Methode qui permet de convertir un pourcentage d’un builder en couleur css/html.
-
.run_command(cmd) ⇒ Object
Methode qui permet de lancer une ligne de commande et de renvoyer son resultat.
-
.verify_gem_presence(gem, auto_install, proxy_option) ⇒ Object
Methode de verification de la presence d’un gem, avec installation au besoin.
Class Method Details
.build_name ⇒ Object
Méthode qui permet de récupérerle numéro de build courant dans le SCM
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/utils.rb', line 64 def self.build_name if File.exist?(".git") return "commit #{Utils.run_command("git log").split(/$/).select{ |l| l =~ /^commit / }.collect { |l| l[8..(l.length-1)] }[0]}" elsif File.exist?(".svn") get_head_log = Utils.run_command("svn log -r HEAD") get_head_log_lines = get_head_log.split(/$/) revision = get_head_log_lines[1].split(/ \| /)[0] revision = revision[2..(revision.length-1)] return "revision #{revision}" end end |
.erb_run(page, is_a_task = true) ⇒ Object
Methode qui permet de construire une page avec eruby, et de lever une exception au besoin
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/utils.rb', line 5 def self.erb_run page, is_a_task = true page_file = File.open("#{Continuous4r::WORK_DIR}/#{page}.html", "w") erb = ERB.new(File.read("#{File.dirname(__FILE__)}/site/header.rhtml")) page_file.write(erb.result) if is_a_task == true erb = ERB.new(File.read("#{File.dirname(__FILE__)}/site/menu-task.rhtml"), 0, "%<>") current_task = page page_file.write(erb.result(binding)) else erb = ERB.new(File.read("#{File.dirname(__FILE__)}/site/menu-#{page}.rhtml"), 0, "%<>") page_file.write(erb.result) end erb = ERB.new(File.read("#{File.dirname(__FILE__)}/site/body-#{page}.rhtml")) page_file.write(erb.result) page_file.close end |
.flog_caracteristics(flog_score) ⇒ Object
Méthode qui permet de typer une cellule de table HTML en fonction d’un score flog
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/utils.rb', line 77 def self.flog_caracteristics(flog_score) if flog_score >= 0 and flog_score < 11 "title='Awesome'" elsif flog_score >= 11 and flog_score < 21 "title='Good enough'" elsif flog_score >= 21 and flog_score < 41 "style='background-color: #FFFF99; color: black;' title='Might need refactoring'" elsif flog_score >= 41 and flog_score < 61 "style='background-color: yellow; color: black;' title='Possible to justify'" elsif flog_score >= 61 and flog_score < 100 "style='background-color: orange; color: black;' title='Danger'" elsif flog_score >= 100 and flog_score < 200 "style='background-color: red; color: black;' title='Whoop, whoop, whoop'" elsif flog_score > 200 "style='background-color: black; color: white;' title='Someone please think of the children'" end end |
.flog_score_to_css_style(flog_score) ⇒ Object
Methode qui permet de convertir un score flog en couleur css/html de titre
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/utils.rb', line 96 def self.flog_score_to_css_style(flog_score) style = "style='font-weight: bold; " if flog_score >= 0 and flog_score < 11 style += "background-color: #00cc00;' title='Awesome'" elsif flog_score >= 11 and flog_score < 21 style += "background-color: #00cc00;' title='Good enough'" elsif flog_score >= 21 and flog_score < 41 style += "background-color: #ffff99;' title='Might need refactoring'" elsif flog_score >= 41 and flog_score < 61 style += "background-color: yellow;' title='Possible to justify'" elsif flog_score >= 61 and flog_score < 100 style += "background-color: orange;' title='Danger'" elsif flog_score >= 100 and flog_score < 200 style += "background-color: red;' title='Whoop, whoop, whoop'" elsif flog_score > 200 style += "background-color: red; color: black; text-decoration: blink;' title='Someone please think of the children'" end return style end |
.percent_to_css_style(percent) ⇒ Object
Methode qui permet de convertir un pourcentage d’un builder en couleur css/html
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/utils.rb', line 49 def self.percent_to_css_style(percent) style = "style='font-weight: bold; color: " if percent >= 90 and percent <= 100 style += "#00cc00;'" elsif percent >= 80 and percent < 90 style += "yellow;'" elsif percent >= 60 and percent < 80 style += "red;'" elsif percent >= 0 and percent < 60 style += "red; text-decoration: blink;'" end return style end |
.run_command(cmd) ⇒ Object
Methode qui permet de lancer une ligne de commande et de renvoyer son resultat
23 24 25 26 27 28 29 |
# File 'lib/utils.rb', line 23 def self.run_command(cmd) if Config::CONFIG['host_os'] =~ /mswin/ `cmd.exe /C #{cmd}` else `#{cmd}` end end |
.verify_gem_presence(gem, auto_install, proxy_option) ⇒ Object
Methode de verification de la presence d’un gem, avec installation au besoin
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/utils.rb', line 32 def self.verify_gem_presence(gem, auto_install, proxy_option) gem_version = run_command("gem list #{gem}") if gem_version.nil? or gem_version.strip.empty? if auto_install == "true" puts " Installing #{gem}..." gem_installed = Utils.run_command("#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}") if gem_installed.index("installed").nil? raise " Install for #{gem} failed with command '#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}'\n BUILD FAILED." end else raise " You don't seem to have #{gem} installed. You can install it with '#{"sudo " unless Config::CONFIG['host_os'] =~ /mswin/}gem install #{gem}#{proxy_option}'.\n BUILD FAILED." end end end |