Module: Generator::Util
- Included in:
- Generator
- Defined in:
- lib/fusegen/util.rb
Instance Method Summary collapse
- #copy_from_repo(source, destination, options = {}) ⇒ Object
- #get_quickstarts(options = {}) ⇒ Object
- #get_substitution_value(keyword, options = {}) ⇒ Object
- #get_version(project_version, component, composite = true) ⇒ Object
- #initialize ⇒ Object
- #load_file(file, options = {}) ⇒ Object
- #say_error(name) ⇒ Object
- #say_info(name) ⇒ Object
- #say_task(name) ⇒ Object
- #say_warn(name) ⇒ Object
Instance Method Details
#copy_from_repo(source, destination, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fusegen/util.rb', line 24 def copy_from_repo(source, destination, = {}) base = [:gitbase] unless [:gitbase].nil? prefix = "" # true when creating a new project if [:category] != "none" && [:name] base = base + [:category] + '/' + [:name] + '/' prefix = [:name] + '/' end begin #remove_file destination if base =~ /http/ get base + source, prefix + destination, else copy_file base + source, prefix + destination, end rescue Exception => e say_error "Unable to load " + base + source if [:debug] puts e. puts e.backtrace end end end |
#get_quickstarts(options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fusegen/util.rb', line 105 def get_quickstarts(={}) repos = load_file "~/.fusegen/repos" quickstarts = {} repos.each do |key, value| # load the index index = load_file "~/.fusegen/#{value["meta"]}/index" = index["meta"] # refresh index if its expired if && ["expires"] < Time.now [:gitbase] = ["baseuri"] do_repo_add ["baseuri"], index = load_file "~/.fusegen/#{value["meta"]}/index" end index["quickstarts"].each do |category, | .each do |template| template["repo"] = value["meta"] template["baseuri"] = index["meta"]["baseuri"] template["category"] = category if quickstarts[category].nil? then quickstarts[category] = []; end quickstarts[category] << template end end end quickstarts end |
#get_substitution_value(keyword, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fusegen/util.rb', line 68 def get_substitution_value(keyword, ={}) case keyword when "@project_version" [:projectversion] when "@package" [:groupid] when "@package_reverse" [:groupid].split(".").reverse.join(".") when "@group_id" [:groupid] when "@artifact_id" [:artifactid] when "@packaging" [:packaging] when "@project_version" [:projectversion] when "@name" [:name] when "@camel_version" get_version([:fuseversion],"camel") when "@activemq_version" get_version([:fuseversion],"activemq") when "@cxf_version" get_version([:fuseversion],"cxf") when "@smx_version" get_version([:fuseversion],"smx") when "@karaf_version" get_version([:fuseversion],"karaf") when "@spring_version" get_version([:fuseversion],"spring",false) when "@fabric_host" "@" + [:fabrichost] else keyword end end |
#get_version(project_version, component, composite = true) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/fusegen/util.rb', line 137 def get_version(project_version, component, composite=true) if composite @versions[project_version[0..1]][component] + project_version else @versions[project_version[0..1]][component] end end |
#initialize ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fusegen/util.rb', line 10 def initialize super @versions = { "60"=> { "camel"=>"2.10.0.redhat-", "activemq"=>"5.8.0.redhat-", "cxf"=>"2.6.0.redhat-", "spring"=>"3.1.3.RELEASE", "karaf"=>"2.3.0.redhat-" }, "61"=> { "camel"=>"2.12.0.redhat-", "activemq"=>"5.9.0.redhat-", "cxf"=>"2.7.0.redhat-", "spring"=>"3.2.3.RELEASE", "karaf"=>"2.3.0.redhat-" } } end |
#load_file(file, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fusegen/util.rb', line 51 def load_file(file, ={}) begin cfg = {} if file =~ /~/ file[0] = '' file = File.('~') + file end if [:name] file = [:name] + '/' + file end cfg = YAML.load_file(file) rescue Exception => e end cfg end |
#say_error(name) ⇒ Object
157 158 159 |
# File 'lib/fusegen/util.rb', line 157 def say_error(name) say "\033[1m\033[31m" + "error".rjust(10) + "\033[0m" + " #{name}" end |
#say_info(name) ⇒ Object
149 150 151 |
# File 'lib/fusegen/util.rb', line 149 def say_info(name) say "\033[1m\033[36m" + "info".rjust(10) + "\033[0m" + " #{name}" end |
#say_task(name) ⇒ Object
145 146 147 |
# File 'lib/fusegen/util.rb', line 145 def say_task(name) say "\033[1m\033[32m" + "task".rjust(10) + "\033[0m" + " #{name} .." end |
#say_warn(name) ⇒ Object
153 154 155 |
# File 'lib/fusegen/util.rb', line 153 def say_warn(name) say "\033[1m\033[36m" + "warn".rjust(10) + "\033[0m" + " #{name}" end |