Class: Doc::BaseTask
- Inherits:
-
Object
- Object
- Doc::BaseTask
- Defined in:
- lib/doc/base_task.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#dir_name ⇒ Object
readonly
Returns the value of attribute dir_name.
-
#documentor ⇒ Object
readonly
Returns the value of attribute documentor.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #control_files_exist? ⇒ Boolean
- #doc_dir ⇒ Object
- #eql?(other) ⇒ Boolean
- #failed? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(documentor, options) ⇒ BaseTask
constructor
A new instance of BaseTask.
- #loaded_gem_version(gem) ⇒ Object
- #run(force = false) ⇒ Object
- #run? ⇒ Boolean
- #succeeded? ⇒ Boolean
- #symlink_to(path) ⇒ Object
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, ) @documentor = documentor @title = [:title].to_s @dir_name = [:dir_name].to_s doc_dir.touch if doc_dir.exist? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/doc/base_task.rb', line 8 def config @config end |
#dir_name ⇒ Object (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 |
#documentor ⇒ Object (readonly)
Returns the value of attribute documentor.
8 9 10 |
# File 'lib/doc/base_task.rb', line 8 def documentor @documentor end |
#title ⇒ Object (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
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_dir ⇒ Object
16 17 18 |
# File 'lib/doc/base_task.rb', line 16 def doc_dir documentor.docs_dir / dir_name end |
#eql?(other) ⇒ Boolean
46 47 48 |
# File 'lib/doc/base_task.rb', line 46 def eql?(other) config.eql?(other.config) end |
#failed? ⇒ Boolean
84 85 86 |
# File 'lib/doc/base_task.rb', line 84 def failed? @state == :failed end |
#hash ⇒ Object
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
56 57 58 |
# File 'lib/doc/base_task.rb', line 56 def run? config_state_changed? || !control_files_exist? end |
#succeeded? ⇒ Boolean
80 81 82 |
# File 'lib/doc/base_task.rb', line 80 def succeeded? @state == :succeeded end |
#symlink_to(path) ⇒ Object
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 |