Class: Semverve::DocsPublisher

Inherits:
Object
  • Object
show all
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

Classes: Shell, Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|publisher| ... } ⇒ Semverve::DocsPublisher

Initializes a documentation publisher.

Yield Parameters:



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_dirtyBoolean

Whether dirty source working trees are allowed.

Returns:

  • (Boolean)


118
119
120
# File 'lib/semverve/docs_publisher.rb', line 118

def allow_dirty
  @allow_dirty
end

#branchString

Branch that receives generated documentation.

Returns:

  • (String)


94
95
96
# File 'lib/semverve/docs_publisher.rb', line 94

def branch
  @branch
end

#command_runner#run, ...

Command runner used for Git commands.

Returns:

  • (#run, #capture, #success?)


136
137
138
# File 'lib/semverve/docs_publisher.rb', line 136

def command_runner
  @command_runner
end

#commit_messageString

Commit message for generated documentation updates.

Returns:

  • (String)


106
107
108
# File 'lib/semverve/docs_publisher.rb', line 106

def commit_message
  @commit_message
end

#dry_runBoolean

Whether to report changes without committing or pushing.

Returns:

  • (Boolean)


130
131
132
# File 'lib/semverve/docs_publisher.rb', line 130

def dry_run
  @dry_run
end

#output#puts

Output stream for status messages.

Returns:

  • (#puts)


142
143
144
# File 'lib/semverve/docs_publisher.rb', line 142

def output
  @output
end

#pushBoolean

Whether the publishing branch should be pushed.

Returns:

  • (Boolean)


124
125
126
# File 'lib/semverve/docs_publisher.rb', line 124

def push
  @push
end

#remoteString

Remote used when pushing the publishing branch.

Returns:

  • (String)


100
101
102
# File 'lib/semverve/docs_publisher.rb', line 100

def remote
  @remote
end

#rootString

Source project root.

Returns:

  • (String)


76
77
78
# File 'lib/semverve/docs_publisher.rb', line 76

def root
  @root
end

#source_dirString

Directory containing generated documentation, relative to root.

Returns:

  • (String)


82
83
84
# File 'lib/semverve/docs_publisher.rb', line 82

def source_dir
  @source_dir
end

#target_dirString

Documentation directory on the publishing branch.

Returns:

  • (String)


88
89
90
# File 'lib/semverve/docs_publisher.rb', line 88

def target_dir
  @target_dir
end

#worktree_pathString?

Optional path for the temporary worktree.

Returns:

  • (String, nil)


112
113
114
# File 'lib/semverve/docs_publisher.rb', line 112

def worktree_path
  @worktree_path
end

Instance Method Details

#publishBoolean

Publishes generated documentation.

Returns:

  • (Boolean)

    whether documentation changes were found



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