Class: Doc::Documentor

Inherits:
Object
  • Object
show all
Defined in:
lib/doc/documentor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arguments, &block) ⇒ Documentor

Returns a new instance of Documentor.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/doc/documentor.rb', line 8

def initialize(*arguments, &block)
  @started = Time.now

  config = RootConfig.new(self, *arguments, &block)
  config.check_options!([], [:title, :min_update_interval, :clean_after, :public_dir])

  @title = config[:title] || 'ruby documentation'
  @min_update_interval = config[:min_update_interval] || 1.hour
  @clean_after = config[:clean_after]
  @configurators = config.configurators

  @base_dir = FSPath('.').expand_path
  @sources_dir = base_dir / 'sources'
  @docs_dir = base_dir / 'docs'
  if config[:public_dir]
    config[:public_dir] = FSPath(config[:public_dir]).cleanpath.to_s
    if config[:public_dir] == '.'
      raise ConfigError.new(self, "can't use base dir: #{config[:public_dir].inspect}")
    end
    if config[:public_dir].split(FSPath::SEPARATOR_PAT).include?('..')
      raise ConfigError.new(self, ".. in public_dir: #{config[:public_dir].inspect}")
    end
  end
  @public_dir = base_dir / (config[:public_dir] || 'public')
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



7
8
9
# File 'lib/doc/documentor.rb', line 7

def base_dir
  @base_dir
end

#clean_afterObject (readonly)

Returns the value of attribute clean_after.



6
7
8
# File 'lib/doc/documentor.rb', line 6

def clean_after
  @clean_after
end

#configuratorsObject (readonly)

Returns the value of attribute configurators.



6
7
8
# File 'lib/doc/documentor.rb', line 6

def configurators
  @configurators
end

#docs_dirObject (readonly)

Returns the value of attribute docs_dir.



7
8
9
# File 'lib/doc/documentor.rb', line 7

def docs_dir
  @docs_dir
end

#min_update_intervalObject (readonly)

Returns the value of attribute min_update_interval.



6
7
8
# File 'lib/doc/documentor.rb', line 6

def min_update_interval
  @min_update_interval
end

#public_dirObject (readonly)

Returns the value of attribute public_dir.



7
8
9
# File 'lib/doc/documentor.rb', line 7

def public_dir
  @public_dir
end

#sources_dirObject (readonly)

Returns the value of attribute sources_dir.



7
8
9
# File 'lib/doc/documentor.rb', line 7

def sources_dir
  @sources_dir
end

#startedObject (readonly)

Returns the value of attribute started.



7
8
9
# File 'lib/doc/documentor.rb', line 7

def started
  @started
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/doc/documentor.rb', line 6

def title
  @title
end

Instance Method Details

#build(update = false) ⇒ Object



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

def build(update = false)
  root_task = config(update)

  root_task.run

  if clean_after
    candidates = []
    candidates += sources_dir.children if sources_dir.directory?
    candidates += docs_dir.children if docs_dir.directory?
    candidates.each do |dir|
      if started - dir.mtime > clean_after
        dir.rmtree_verbose
      end
    end
  end
end

#config(update = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/doc/documentor.rb', line 34

def config(update = false)
  last_updated_path = base_dir / '.last_updated'
  update ||= last_updated_path.exist? ? (Time.now > last_updated_path.mtime + min_update_interval) : true

  configurators.with_progress('configuring and updating').each do |configurator|
    configurator.configure(update)
  end
  last_updated_path.touch if update

  RootMerger.new(self, {
    :title => title,
    :tasks => configurators.with_progress('generating tasks').map(&:tasks).flatten
  })
end