Module: SdocAll::Ruby::ClassMethods

Included in:
SdocAll::Ruby
Defined in:
lib/sdoc_all/parts/ruby.rb

Instance Method Summary collapse

Instance Method Details

#download_matching_archive(version) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sdoc_all/parts/ruby.rb', line 173

def download_matching_archive(version)
  Net::FTP.open('ftp.ruby-lang.org') do |ftp|
    remote_path = '/pub/ruby'
    ftp.debug_mode = true
    ftp.passive = true
    ftp.
    ftp.chdir(remote_path)
    paths = ftp.list('ruby-*.tar.bz2').map{ |line| "#{remote_path}/#{line.split.last}" }

    if tar = last_matching_ruby_archive(version, paths)
      dest = sources_path.parent + tar.name
      unless File.exist?(dest) && File.size(dest) == ftp.size(tar.path)
        ftp.getbinaryfile(tar.path, dest)
      end
    end
  end
end

#find_matching_archive(version) ⇒ Object



168
169
170
171
# File 'lib/sdoc_all/parts/ruby.rb', line 168

def find_matching_archive(version)
  paths = sources_path.parent.children.select(&:file?)
  last_matching_ruby_archive(version, paths)
end

#find_or_download_matching_archive(version, options = {}) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/sdoc_all/parts/ruby.rb', line 191

def find_or_download_matching_archive(version, options = {})
  if options[:update] || (archive = find_matching_archive(version)).nil?
    download_matching_archive(version)
    if (archive = find_matching_archive(version)).nil?
      raise ConfigError.new("could not find version of ruby matching #{version.inspect}")
    end
  end
  archive
end

#last_matching_ruby_archive(version, paths) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/sdoc_all/parts/ruby.rb', line 160

def last_matching_ruby_archive(version, paths)
  paths.map do |path|
    match_ruby_archive(path)
  end.compact.sort_by(&:version).reverse.find do |tar_info|
    tar_info.full_version.starts_with?(version)
  end
end

#match_ruby_archive(path) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/sdoc_all/parts/ruby.rb', line 147

def match_ruby_archive(path)
  name = File.basename(path)
  if match = /^ruby-((\d+\.\d+\.\d+)-p(\d+))(?:\.(tar\.(?:gz|bz2)|zip))$/.match(name)
    ArchiveInfo.new.tap do |i|
      i.path = path
      i.name = name
      i.full_version = match[1]
      i.extension = match[4]
      i.version = match[2].split('.').map(&:to_i) << match[3].to_i
    end
  end
end