Class: CapsuleCD::Ruby::RubyHelper
- Inherits:
-
Object
- Object
- CapsuleCD::Ruby::RubyHelper
- Defined in:
- lib/capsulecd/ruby/ruby_helper.rb
Class Method Summary collapse
-
.execute_in_child ⇒ Object
since the Gem::Specification class is basically eval’ing the gemspec file, and the gemspec file is doing a require to load the version.rb file, the version.rb file is cached in memory.
- .get_gemspec_data(repo_path) ⇒ Object
- .get_gemspec_path(repo_path) ⇒ Object
- .load_gemspec_data(gemspec_path) ⇒ Object
- .read_version_file(repo_path, gem_name, version_filename = 'version.rb') ⇒ Object
- .version_filepath(repo_path, gem_name, version_filename = 'version.rb') ⇒ Object
- .write_version_file(repo_path, gem_name, metadata_str, version_filename = 'version.rb') ⇒ Object
Class Method Details
.execute_in_child ⇒ Object
since the Gem::Specification class is basically eval’ing the gemspec file, and the gemspec file is doing a require to load the version.rb file, the version.rb file is cached in memory. We’re going to try to get around that issue by parsing the gemspec file in a forked process. stackoverflow.com/questions/1076257/returning-data-from-forked-processes
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 37 def self.execute_in_child read, write = IO.pipe pid = fork do read.close result = yield Marshal.dump(result, write) exit!(0) # skips exit handlers. end write.close result = read.read Process.wait(pid) raise "child failed" if result.empty? Marshal.load(result) end |
.get_gemspec_data(repo_path) ⇒ Object
26 27 28 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 26 def self.get_gemspec_data(repo_path) self.load_gemspec_data(self.get_gemspec_path(repo_path)) end |
.get_gemspec_path(repo_path) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 18 def self.get_gemspec_path(repo_path) gemspecs = Dir.glob(repo_path + '/*.gemspec') if gemspecs.empty? fail CapsuleCD::Error::BuildPackageInvalid, '*.gemspec file is required to process Ruby gem' end gemspecs.first end |
.load_gemspec_data(gemspec_path) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 54 def self.load_gemspec_data(gemspec_path) gemspec_data = nil Bundler.with_clean_env do gemspec_data = self.execute_in_child do Gem::Specification::load(gemspec_path) end end if !gemspec_data fail CapsuleCD::Error::BuildPackageInvalid, '*.gemspec could not be parsed.' end return gemspec_data end |
.read_version_file(repo_path, gem_name, version_filename = 'version.rb') ⇒ Object
10 11 12 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 10 def self.read_version_file(repo_path, gem_name, version_filename = 'version.rb') File.read(self.version_filepath(repo_path, gem_name, version_filename)) end |
.version_filepath(repo_path, gem_name, version_filename = 'version.rb') ⇒ Object
6 7 8 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 6 def self.version_filepath(repo_path, gem_name, version_filename = 'version.rb') "#{repo_path}/lib/#{gem_name}/#{version_filename}" end |
.write_version_file(repo_path, gem_name, metadata_str, version_filename = 'version.rb') ⇒ Object
14 15 16 |
# File 'lib/capsulecd/ruby/ruby_helper.rb', line 14 def self.write_version_file(repo_path, gem_name, , version_filename = 'version.rb') File.open(self.version_filepath(repo_path, gem_name, version_filename), 'w') { |file| file.write() } end |