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.



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

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.



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

def config
  @config
end

#dir_nameObject (readonly)

Returns the value of attribute dir_name.



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

def dir_name
  @dir_name
end

#documentorObject (readonly)

Returns the value of attribute documentor.



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

def documentor
  @documentor
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.state_methods(name, data_code_for_state) ⇒ Object



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

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? || Marshal.load(#{name}_state_path.read) != #{name}_state
    rescue true
    end
    def write_#{name}_state
      #{name}_state_path.write(Marshal.dump(#{name}_state))
    end
  RUBY
end

Instance Method Details

#control_files_exist?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/doc/base_task.rb', line 47

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

#doc_dirObject



14
15
16
# File 'lib/doc/base_task.rb', line 14

def doc_dir
  documentor.docs_dir / dir_name
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#failed?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/doc/base_task.rb', line 73

def failed?
  @state == :failed
end

#hashObject



40
41
42
# File 'lib/doc/base_task.rb', line 40

def hash
  config.hash
end

#loaded_gem_version(gem) ⇒ Object



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

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

#run(force = false) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/doc/base_task.rb', line 58

def run(force = false)
  if force || run?
    doc_dir.rmtree_verbose if doc_dir.exist?
    build
    write_config_state
    @state = control_files_exist? ? :succeeded : :failed
  end
rescue SystemExit
  @state = :failed
end

#run?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/doc/base_task.rb', line 53

def run?
  config_state_changed? || !control_files_exist?
end

#succeeded?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/doc/base_task.rb', line 69

def succeeded?
  @state == :succeeded
end