Class: Grepgems
- Inherits:
-
Object
- Object
- Grepgems
- Defined in:
- lib/gemlocker.rb
Instance Method Summary collapse
-
#description ⇒ Object
:nodoc:.
- #grep_libfiles ⇒ Object
-
#initialize ⇒ Grepgems
constructor
A new instance of Grepgems.
- #purge_tempfiles ⇒ Object
Constructor Details
#initialize ⇒ Grepgems
Returns a new instance of Grepgems.
197 198 199 200 201 202 203 204 |
# File 'lib/gemlocker.rb', line 197 def initialize @code_path = ARGV @tmp_files =['gemlist.log','libfiles.log','errors.log'] purge_tempfiles; @which_cmd = Whichgem.new; @lock_cmd=LockCommand.new; @out_file_path = Dir.pwd; end |
Instance Method Details
#description ⇒ Object
:nodoc:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/gemlocker.rb', line 205 def description # :nodoc: puts " -------Usage ----- gemlocker [DIR1] [DIR2] [DIR3] [DIR...... Please supply at least one directory path. USES OF GEMLOCKER: ----------------- 1. To avoid problems with new versions of a gem by loading a specific versions of gem; 2. To list all dependencies - useful while building a gem/ rake file More details.. -------------- The gemlocker command will generate a list of +gem+ statements that will lock down the versions for the gem used in the files of the given paths in the command line. It will specify exact versions in the requirements list to ensure that the gems loaded will always be consistent. A full recursive search of all effected gems will be generated. It generates 4 files gemlist.log; errors.log; libfiles.log; and gem_lockdown.rb gemlist.log: contains all lib files used in the files of given path; errors.log : contains all errors - Normally user defined lib files etc.. libfiles.log : lists all lib files-paths gem_lockdown.rb : contains all gems and their latest versions. It is similar to gem lock command; where gemlock generates lock down list for a given gem; and gemlock generates lock down list for all gems used in a directory (of files.) Example: gemlocker /home/us/progdir . .. will list out all dependencies in gem_lockdown.rb in invokation directory by looking at the 'require' statements/lib files used in your projects located in /home/us/progdir , current directory, .. and all their subdirectories; gem_lockdown.rb will look like below require 'rubygems' gem 'rails', '= 1.0.0' gem 'rake', '= 0.7.0.1' gem 'activesupport', '= 1.2.5' gem 'activerecord', '= 1.13.2' gem 'actionpack', '= 1.11.2' gem 'actionmailer', '= 1.1.5' gem 'actionwebservice', '= 1.0.0' Just load gem_lockdown.rb from your application to ensure that the currect versions are loaded. Make sure that lockdown.rb is loaded *before* any other require statements. Note : if you are not using latest versions of gems in your files(project), you may have to edit gem_lockdown.rb to load the desired versions. example scenario: If you are using activerecord-1.0.2 and your system is installed with activerecord-2.2.3 then gem_lockdown.rb will show only 2.2.3; so, you will have to edit the gem_lockdown.rb to modify the version of activerecord to 1.0.2 " end |
#grep_libfiles ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/gemlocker.rb', line 260 def grep_libfiles libs=[] @code_path.each { |p| rbfiles = File.join(p,"**", "*.*") Dir.glob(rbfiles) {|file| #puts file; f=File.open(file,"r") if File.file?(File.(file)); if f then while(row = f.gets) row.scan(/require\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # getting single quoted requires row.scan(/require\s\"\w+\"/) {|m| s= m.split('"'); libs <<s.last;} # gettin double quoted requires row.scan(/rrequire\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get command line requires row.scan(/gem\s\'\w+\'/) {|m| s=m.split("'"); libs<<s.last;} # get external gem requires. end f.close end } } puts "-----------------------","list of requires", "-----------------------",libs.join( ' '); @lock_cmd.execute(@out_file_path,@which_cmd.execute(libs,@out_file_path)); end |
#purge_tempfiles ⇒ Object
281 282 283 |
# File 'lib/gemlocker.rb', line 281 def purge_tempfiles @tmp_files.each {|f| File.delete(f) if File.file?(f) ;} end |