Class: Dev::Project
Instance Method Summary collapse
- #array_method(name) ⇒ Object
- #bundle_gems ⇒ Object
- #commit ⇒ Object
- #expand_command(command) ⇒ Object
- #expand_project_variables(str) ⇒ Object
- #features ⇒ Object
- #get_default_value(key) ⇒ Object
- #info ⇒ Object
-
#initialize(hash, init_defaults = true) ⇒ Project
constructor
A new instance of Project.
- #loc ⇒ Object
- #loc_cmd ⇒ Object
- #loc_total ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #set_default_value(key) ⇒ Object
- #update_default_values ⇒ Object
Methods inherited from Hash
get_hash_value, #get_value, print_hash, set_hash_value, #set_value
Constructor Details
#initialize(hash, init_defaults = true) ⇒ Project
Returns a new instance of Project.
10 11 12 13 14 |
# File 'lib/dev/Project.rb', line 10 def initialize(hash,init_defaults=true) puts_debug "initialize, copying hash values" hash.each { |name,value| self[name]=value } update_default_values if init_defaults end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
38 39 40 |
# File 'lib/dev/Project.rb', line 38 def method_missing( name, *args ) array_method(name) end |
Instance Method Details
#array_method(name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dev/Project.rb', line 16 def array_method(name) string_name=name.to_s puts_debug "method_missing name=" + string_name if(self.get_value(string_name).nil? || self.get_value(string_name).length < 1) puts_debug "no directives defined for method #{string_name}" return end puts_debug "found directives for #{string_name}: #{self.get_value(string_name).to_s}" puts string_name.foreground(:yellow).bright self.get_value(string_name).each{ |c| # expand the command here.... command=(c) if c.include?('<%') && c.include?('%>') puts "Command: " + c eval(c.gsub("<%","").gsub("%>","")) else call=Dev::SystemCall.new(command) call.puts_summary end } end |
#bundle_gems ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/dev/Project.rb', line 108 def bundle_gems if(File.exists?("Gemfile")) call=Dev::SystemCall.new("bundle install") puts call.Summary elsif(File.exists?("lib/Gemfile")) pwd=Dir.pwd Dir.chdir("lib") call=Dev::SystemCall.new("bundle install") Dir.chdir(pwd) call.puts_summary else throw "no Gemfile found to bundle" end end |
#commit ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dev/Project.rb', line 91 def commit call=nil call=Dev::SystemCall.new('git diff') if File.exists?(".git") call=Dev::SystemCall.new('svn diff') if File.exists?(".svn") unless call.nil? || call.output.length==0 array_method("commit") else puts " no differences detected" end end |
#expand_command(command) ⇒ Object
42 43 44 45 |
# File 'lib/dev/Project.rb', line 42 def (command) result=(command) return result end |
#expand_project_variables(str) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dev/Project.rb', line 47 def (str) result=Dev::Environment.(str) # expands ruby variables, e.g. '#{name}' to 'widget' if result.include?('<') && result.include?('>') result.scan(/(<[\w,]+>)/).each { |pvar| # expand project variables, e.g. '<name>' to 'widget key = pvar[0].gsub("<","").gsub(">","") # '<paths,nunit>' to 'C:/wherever/NUnit.exe' result = result.gsub(pvar[0],get_value(key)) } end result end |
#features ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dev/Project.rb', line 80 def features if self[:type]=="C#" && File.exists?("bin/x86/Release/#{self[:name]}.Features.dll") call=Dev::SystemCall.new(("<paths,nunit> /nologo bin/x86/Release/#{self[:name]}.Features.dll")) puts call.command puts call.output raise "exit_code=#{call.status.to_s}" + call.error unless call.status==0 end array_method("features") end |
#get_default_value(key) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/dev/Project.rb', line 127 def get_default_value(key) system_call = Dev::SystemCall.new("semver init") if(!File.exist?(".semver")) version = SemVer.find value="#{Dev::Environment.dev_root}" if key=="dev_root" value="C#" if key=="type" value="**/*.{cs,xaml,rb,resx,settings,feature,semver}" if key=="src_glob" && self[:type]=="C#" value="**/*.{rb,feature,semver}" if key=="src_glob" && self[:type]=="ruby" value="**/*.{rb,feature,gemspec,semver}" if key=="src_glob" && self[:type]=="gem" value=Dir.glob(self[:src_glob]).length.to_s if key=="file_count" value=loc_total if key=="loc" value="svn" if key=="scm_type" && File.exists?(".svn") value="git" if key=="scm_type" && File.exists?(".git") value="#{version.major}.#{version.minor}.#{version.patch}" if key=="version" hash=Hash.new if(key=="paths") if(self[:type]=="C#") hash.set_value("msbuild","C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe") nunit_version="2.5.10.11092" hash.set_value("nunit","#{Dev::Environment.dev_root}/dep/ThirdParty/NUnit/#{nunit_version}/bin/net-2.0/nunit-console-x86.exe") end end value=hash if hash.length > 0 array=Array.new if(key=="bootstrap") #array=Array.new array << "bundle install" if File.exists?("Gemfile") # dep,svn directives dep_hash=self.get_value("dep") unless dep_hash.nil? dep_hash.each do |key,value| if value.kind_of?(Hash) # potential hash keys: uri, dir # uri is required unless value.get_value("uri").nil? uri=(value.get_value("uri")) uri_words=uri.split('/') while(uri_words.length > 3) do uri_words.shift end dir=uri_words.join('/') dir=(value.get_value("dir")) unless value.get_value("dir").nil? dir=self[:dev_root] + "/dep/" + dir unless dir.include?(self[:dev_root]) array << "svn export " + (value.get_value("uri")) + " " + dir unless File.exists?(dir) array << "<%puts ' #{dir} exists.'%>" if File.exists?(dir) end end end end #bootstrap << "cd lib" if File.exists?("lib/Gemfile") #bootstrap << "cd lib;bundle install;cd .." if File.exists?("lib/Gemfile") #bootstrap << "cd .." if File.exists?("lib/Gemfile") #bootstrap << "<%exec_in_dir('bundle install','lib')%>" if File.exists?("lib/Gemfile") end if(key=="compile") Dir.glob("*.gemspec").each { |gs| array << "gem build #{gs}" } if self[:type]=="gem" if self[:type]=="C#" if(!has_key?(:x86_release_compile_flags)) self[:x86_release_compile_flags]="/property:Configuration=Release /property:Platform=\"x86\" /p:OutputPath=./bin/x86/Release" end end Dir.glob("*.csproj").each{|cs|array<<"<paths,msbuild> #{cs} <x86_release_compile_flags>"} end if(key=="test") Dir.glob("*.gemspec").each { |gs| array << "gem uninstall #{gs.gsub('.gemspec','')} -v #{self[:version]}" } if self[:type]=="gem" Dir.glob("*.gemspec").each { |gs| array << "gem install ./#{gs.gsub('.gemspec','')}-#{self[:version]}.gem" } if self[:type]=="gem" if self[:type]=="C#" Dir.glob("*.{Test.csproj,Features.csproj}").each { |cs| dll_name="bin/x86/Release/#{File.basename(cs,'.csproj')}.dll" array << "<paths,nunit> /nologo #{dll_name} /xml:#{dll_name}.nunit-results.xml" } end end if(key=="features") array << "cucumber features" if File.exists?("features") && Dir.glob("features/**/*.rb").length > 0 end if(key=="has_diff") array << 'git diff' if File.exists?(".git") array << 'svn diff' if File.exists?(".svn") end if(key=="commit") array << 'git commit -a -m "rake commit all"' if File.exists?(".git") array << 'svn commit -m "rake commit all"' if File.exists?(".svn") end value=array if array.length > 0 return value end |
#info ⇒ Object
102 103 104 105 106 |
# File 'lib/dev/Project.rb', line 102 def info puts " " Hash.print_hash("",self) puts " " end |
#loc ⇒ Object
66 67 68 |
# File 'lib/dev/Project.rb', line 66 def loc system(loc_cmd) end |
#loc_cmd ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/dev/Project.rb', line 58 def loc_cmd cmd="countloc --recurse ." cmd="countloc --recurse --mode ruby ." if self[:type]=="ruby" || self[:type]=="gem" cmd="countloc --recurse --mode csharp ." if self[:type]=="C#" cmd="countloc --recurse --mode cpp ." if self[:type]=="c++" return cmd end |
#loc_total ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/dev/Project.rb', line 70 def loc_total # parse the output for TOTAL LOC call=Dev::SystemCall.new(loc_cmd) words=call.output.split if(words.length>6) return words[words.length-6] end "?" end |
#set_default_value(key) ⇒ Object
123 124 125 |
# File 'lib/dev/Project.rb', line 123 def set_default_value(key) set_value(key,get_default_value(key)) if get_value(key).nil? && !get_default_value(key).nil? end |
#update_default_values ⇒ Object
227 228 229 230 231 232 |
# File 'lib/dev/Project.rb', line 227 def update_default_values puts_debug "update_default_values" [ "type","version","dev_root","src_glob","file_count","loc","scm_type", "paths","bootstrap","compile","test","features","commit" ].each { |k| set_default_value(k) } end |