Class: RDoc::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc/data.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'4.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Data

Returns a new instance of Data.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rdoc/data.rb', line 49

def initialize options
  data_dir = Gem.datadir('') || File.expand_path('../../../data', __FILE__)
  version = RUBY_VERSION.dup[0..-3] # strip the patch-level
  @source = File.join data_dir, version

  unless File.exist? @source then
    supported = Dir[File.join(data_dir, '*')].map do |dir|
      dir.sub File.join(data_dir, ''), ''
    end.sort

    raise Error, "Your ruby version #{version} is not supported, " \
                 "only #{supported.join ', '}"
  end

  @destination = RDoc::RI::Paths.system_dir
end

Class Method Details

.process_args(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rdoc/data.rb', line 13

def self.process_args args
  options = {}

  if args.empty? or args.include? '--help' or
     not args.include? '--install' then
    puts "Usage: #{$0} [--verbose] [--dryrun] --install"
    puts
    puts "Installs updated ruby #{RUBY_VERSION} system ri data (core + stdlib)"
    exit 1
  elsif args.include? '--verbose' then
    options[:verbose] = true
  elsif args.include? '--dryrun' then
    options[:dryrun] = true
  end

  options
end

.run(argv = ARGV) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rdoc/data.rb', line 31

def self.run argv = ARGV
  options = process_args argv

  data = new options

  if options[:dryrun] then
    data.extend FileUtils::DryRun
  elsif options[:verbose] then
    data.extend FileUtils::Verbose
  else
    data.extend FileUtils
  end

  data.run
rescue Error => e
  abort e.message
end

Instance Method Details

#runObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rdoc/data.rb', line 66

def run
  cd @source do
    files = Dir[File.join('**', '*.ri{d,}')]

    files.each do |file|
      dest_file = File.join @destination, file
      dest_dir = File.dirname dest_file

      mkdir_p dest_dir
      install file, dest_dir, :mode => 0644
    end
  end
end