Class: Doc::BaseTask

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

Direct Known Subclasses

Builder, Merger

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(documentor, options) ⇒ BaseTask

Returns a new instance of BaseTask.



9
10
11
12
13
14
# File 'lib/doc/base_task.rb', line 9

def initialize(documentor, options)
  @documentor = documentor
  @title = options[:title].to_s
  @dir_name = options[:dir_name].to_s
  doc_dir.touch if doc_dir.exist?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/doc/base_task.rb', line 8

def config
  @config
end

#dir_nameObject (readonly)

Returns the value of attribute dir_name.



8
9
10
# File 'lib/doc/base_task.rb', line 8

def dir_name
  @dir_name
end

#documentorObject (readonly)

Returns the value of attribute documentor.



8
9
10
# File 'lib/doc/base_task.rb', line 8

def documentor
  @documentor
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/doc/base_task.rb', line 8

def title
  @title
end

Class Method Details

.state_methods(name, data_code_for_state) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/doc/base_task.rb', line 20

def self.state_methods(name, data_code_for_state)
  class_eval <<-RUBY, __FILE__, __LINE__
    def #{name}_state
      @#{name}_state ||= #{data_code_for_state}
    end
    def #{name}_state_path
      doc_dir / '.#{name}_state'
    end
    def #{name}_state_changed?
      !#{name}_state_path.exist? || YAML.load(#{name}_state_path.read) != #{name}_state
    rescue
      true
    end
    def write_#{name}_state
      #{name}_state_path.write(YAML.dump(#{name}_state))
    end
  RUBY
end

Instance Method Details

#control_files_exist?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/doc/base_task.rb', line 50

def control_files_exist?
  %w[created.rid index.html].all? do |name|
    (doc_dir / name).exist?
  end
end

#doc_dirObject



16
17
18
# File 'lib/doc/base_task.rb', line 16

def doc_dir
  documentor.docs_dir / dir_name
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/doc/base_task.rb', line 46

def eql?(other)
  config.eql?(other.config)
end

#failed?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/doc/base_task.rb', line 84

def failed?
  @state == :failed
end

#hashObject



43
44
45
# File 'lib/doc/base_task.rb', line 43

def hash
  config.hash
end

#loaded_gem_version(gem) ⇒ Object



88
89
90
# File 'lib/doc/base_task.rb', line 88

def loaded_gem_version(gem)
  Gem.loaded_specs[gem].version
end

#run(force = false) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/doc/base_task.rb', line 61

def run(force = false)
  if force || run?
    if doc_dir.exist?
      $stderr.puts %W[rm -r #{doc_dir}].shelljoin
      doc_dir.rmtree
    end
    Progress.note = title
    build
    write_config_state
    @state = control_files_exist? ? :succeeded : :failed
  end
rescue SystemExit
  @state = :failed
end

#run?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/doc/base_task.rb', line 56

def run?
  config_state_changed? || !control_files_exist?
end

#succeeded?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/doc/base_task.rb', line 80

def succeeded?
  @state == :succeeded
end


76
77
78
# File 'lib/doc/base_task.rb', line 76

def symlink_to(path)
  (path / doc_dir.basename).make_symlink(doc_dir.relative_path_from(path))
end