Class: LockCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- LockCommand
- Defined in:
- lib/gemlocker.rb
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
- #complain(message) ⇒ Object
-
#defaults_str ⇒ Object
:nodoc:.
- #execute(out_file_path, x) ⇒ Object
-
#initialize ⇒ LockCommand
constructor
A new instance of LockCommand.
- #spec_path(gem_full_name) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ LockCommand
Returns a new instance of LockCommand.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gemlocker.rb', line 10 def initialize super 'lock', 'Generate a lockdown list of gems', :strict => false add_option '-s', '--[no-]strict', 'fail if unable to satisfy a dependency' do |strict, | [:strict] = strict end end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/gemlocker.rb', line 22 def arguments # :nodoc: "GEMNAME name of gem to lock\nVERSION version of gem to lock" end |
#complain(message) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gemlocker.rb', line 34 def complain() if [:strict] then raise Gem::Exception, else say "# #{message}" end end |
#defaults_str ⇒ Object
:nodoc:
26 27 28 |
# File 'lib/gemlocker.rb', line 26 def defaults_str # :nodoc: "--no-strict" end |
#execute(out_file_path, x) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 |
# File 'lib/gemlocker.rb', line 42 def execute(out_file_path,x) fgl = File.open(File.join(out_file_path, "gem_lockdown.rb"), "w"); if !fgl then say " gem_lockdown.rb is not writable"; else fgl.puts"require 'rubygems'" end pending = []; locked = {} gemlist_file = File.join(out_file_path,"gemlist.log") if (File.file?(gemlist_file) && File.readable?(gemlist_file)) then f = File.open(gemlist_file,"r"); while (gemx=f.gets) do pending " end\n else\n puts \"cant open gemlist file\"\n return\n end\n \n puts \"-----------------------------------------------------------\",\"direct dependencies ... \#{pending.size}\",\"-----------------------------------------------------------\";\n \n until pending.empty? do\n full_name = pending.shift\n \n spec = Gem::SourceIndex.load_specification spec_path(full_name)\n \n if spec.nil? then\n complain \"Could not find gem \#{full_name}, try using the full name\"\n next\n end\n fgl.puts \"gem '\#{spec.name}','=\#{spec.version}'\" unless locked[spec.name]\n say \"gem '\#{spec.name}', '= \#{spec.version}'\" unless locked[spec.name]\n locked[spec.name] = true\n\n spec.runtime_dependencies.each do |dep|\n next if locked[dep.name]\n candidates = Gem.source_index.search dep\n\n if candidates.empty? then\n complain \"Unable to satisfy '\#{dep}' from currently installed gems\"\n else\n pending << candidates.last.full_name\n end\n end\n end\n fgl.close\n puts \"-----------------------------------------------------------\",\"gem Lockdown file: \#{File.join(out_file_path, \"gem_lockdown.rb\")}\",\"-----------------------------------------------------------\";\n \nend\n".strip |
#spec_path(gem_full_name) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/gemlocker.rb', line 96 def spec_path(gem_full_name) gemspecs = Gem.path.map do |path| File.join path, "specifications", "#{gem_full_name}.gemspec" end gemspecs.find { |gemspec| File.exist? gemspec } end |
#usage ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/gemlocker.rb', line 30 def usage # :nodoc: "#{program_name} GEMNAME-VERSION [GEMNAME-VERSION ...]" end |