Class: Semverve::DocsPublisher
- Inherits:
-
Object
- Object
- Semverve::DocsPublisher
- Defined in:
- lib/semverve/docs_publisher.rb,
lib/semverve/docs_publisher/task.rb
Overview
Publishes generated documentation to a Git branch through a temporary worktree.
Defined Under Namespace
Instance Attribute Summary collapse
-
#allow_dirty ⇒ Boolean
Whether dirty source working trees are allowed.
-
#branch ⇒ String
Branch that receives generated documentation.
-
#command_runner ⇒ #run, ...
Command runner used for Git commands.
-
#commit_message ⇒ String
Commit message for generated documentation updates.
-
#dry_run ⇒ Boolean
Whether to report changes without committing or pushing.
-
#output ⇒ #puts
Output stream for status messages.
-
#push ⇒ Boolean
Whether the publishing branch should be pushed.
-
#remote ⇒ String
Remote used when pushing the publishing branch.
-
#root ⇒ String
Source project root.
-
#source_dir ⇒ String
Directory containing generated documentation, relative to
root. -
#target_dir ⇒ String
Documentation directory on the publishing branch.
-
#worktree_path ⇒ String?
Optional path for the temporary worktree.
Instance Method Summary collapse
-
#initialize {|publisher| ... } ⇒ Semverve::DocsPublisher
constructor
Initializes a documentation publisher.
-
#publish ⇒ Boolean
Publishes generated documentation.
Constructor Details
#initialize {|publisher| ... } ⇒ Semverve::DocsPublisher
Initializes a documentation publisher.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/semverve/docs_publisher.rb', line 150 def initialize @root = Dir.pwd @source_dir = "docs" @target_dir = "docs" @branch = "gh-pages" @remote = "origin" @commit_message = "Update generated documentation" @worktree_path = nil @allow_dirty = false @push = true @dry_run = false @command_runner = Shell.new @output = $stdout yield self if block_given? end |
Instance Attribute Details
#allow_dirty ⇒ Boolean
Whether dirty source working trees are allowed.
118 119 120 |
# File 'lib/semverve/docs_publisher.rb', line 118 def allow_dirty @allow_dirty end |
#branch ⇒ String
Branch that receives generated documentation.
94 95 96 |
# File 'lib/semverve/docs_publisher.rb', line 94 def branch @branch end |
#command_runner ⇒ #run, ...
Command runner used for Git commands.
136 137 138 |
# File 'lib/semverve/docs_publisher.rb', line 136 def command_runner @command_runner end |
#commit_message ⇒ String
Commit message for generated documentation updates.
106 107 108 |
# File 'lib/semverve/docs_publisher.rb', line 106 def @commit_message end |
#dry_run ⇒ Boolean
Whether to report changes without committing or pushing.
130 131 132 |
# File 'lib/semverve/docs_publisher.rb', line 130 def dry_run @dry_run end |
#output ⇒ #puts
Output stream for status messages.
142 143 144 |
# File 'lib/semverve/docs_publisher.rb', line 142 def output @output end |
#push ⇒ Boolean
Whether the publishing branch should be pushed.
124 125 126 |
# File 'lib/semverve/docs_publisher.rb', line 124 def push @push end |
#remote ⇒ String
Remote used when pushing the publishing branch.
100 101 102 |
# File 'lib/semverve/docs_publisher.rb', line 100 def remote @remote end |
#root ⇒ String
Source project root.
76 77 78 |
# File 'lib/semverve/docs_publisher.rb', line 76 def root @root end |
#source_dir ⇒ String
Directory containing generated documentation, relative to root.
82 83 84 |
# File 'lib/semverve/docs_publisher.rb', line 82 def source_dir @source_dir end |
#target_dir ⇒ String
Documentation directory on the publishing branch.
88 89 90 |
# File 'lib/semverve/docs_publisher.rb', line 88 def target_dir @target_dir end |
#worktree_path ⇒ String?
Optional path for the temporary worktree.
112 113 114 |
# File 'lib/semverve/docs_publisher.rb', line 112 def worktree_path @worktree_path end |
Instance Method Details
#publish ⇒ Boolean
Publishes generated documentation.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/semverve/docs_publisher.rb', line 171 def publish validate! ensure_clean_source_worktree unless allow_dirty with_worktree do |worktree| sync_docs_to(worktree) unless publishing_worktree_changed?(worktree) output.puts "Documentation is already current on #{branch}." return false end if dry_run output.puts "Documentation changes detected for #{branch}; dry run did not commit or push." return true end commit_docs(worktree) push_docs(worktree) if push output.puts "Published documentation to #{remote}/#{branch}." true end end |