Module: Doc::Configurator::Ruby::Source
- Included in:
- Doc::Configurator::Ruby
- Defined in:
- lib/doc/configurator/ruby/source.rb
Instance Method Summary collapse
- #by_binary(binary, update) ⇒ Object
- #by_version(version, update) ⇒ Object
- #from_archive(path) ⇒ Object
- #from_dir(path) ⇒ Object
Instance Method Details
#by_binary(binary, update) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/doc/configurator/ruby/source.rb', line 11 def by_binary(binary, update) binary = (binary || 'ruby').to_s version = VersionSpecifier.new(`#{binary} -e 'print "\#{RUBY_VERSION}-p\#{RUBY_PATCHLEVEL}"'`) if $?.success? if version.valid? version = version.drop unless version < VersionSpecifier.new(2.1) by_version(version, update) else raise "invalid version from `#{binary}`: #{version.to_s.inspect}" end else raise "failed to get version from `#{binary}`" end end |
#by_version(version, update) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/doc/configurator/ruby/source.rb', line 26 def by_version(version, update) version = VersionSpecifier.new(version) if version.valid? if (update && !version.full_version?) || !path_for_version(version) download_version(version) end if path = path_for_version(version) path.directory? ? from_dir(path) : from_archive(path) else raise "can't get ruby #{version}" end else raise "version should be in format X.Y, X.Y.Z or X.Y.Z-pPPP, download archive if you need release candidate or other version" end end |
#from_archive(path) ⇒ 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 |
# File 'lib/doc/configurator/ruby/source.rb', line 42 def from_archive(path) path = FSPath(path) if path.file? if path.basename.to_s =~ /^(.*)(?i:\.(tar\.(?:gz|bz2)|tgz|tbz|zip))$/ dir, extension = sources_dir / $1, $2.downcase unless dir.exist? FSPath.temp_dir 'ruby', sources_dir do |d| begin case extension when 'tbz', 'tar.bz2' Command.run('tar', '-xjf', path, '-C', d) when 'tgz', 'tar.gz' Command.run('tar', '-xzf', path, '-C', d) when 'zip' Command.run('unzip', '-q', path, '-d', d) end children = d.children if children.length == 1 children.first.rename(dir) else dir.mkpath FileUtils.mv children, dir end rescue SystemExit => e raise "got #{e} trying to extract archive" end end end from_dir(dir) else raise "#{path} doesn't seem to be archive of known type" end else raise "#{path} is not a file" end end |
#from_dir(path) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/doc/configurator/ruby/source.rb', line 80 def from_dir(path) path = FSPath(path) if path.directory? version_path = path / 'version.h' if version_path.file? && version_path.read['RUBY_VERSION'] dot_document_path = path / '.document' if dot_document_path.size? path. else raise "#{path} doesn't contain .document file or it is empty" end else raise "#{path} doesn't contain version.h file or it has no RUBY_VERSION in it" end else raise "#{path} is not a directory" end end |