class GitDS::ExecCmd

A command to be executed in a database context (i.e. an Index).

Usage:

db.exec { |idx| … }

See also Transaction.

Constants

DEFAULT_MESSAGE

Attributes

block[R]

The body of the command.

commit_author[R]

The Git author for the commit performed at the end of the command. See commit_msg.

commit_msg[R]

The message to use for the commit at the end of the command.

database[R]

The GitDS::Database on which the command operates. Useful for nesting.

index[R]

The GitDS::Index on which the command operates.

nested[R]

Is command nested (inside a parent)? If true, a write and commit will not be performed.

Public Class Methods

new(index, nested, msg=DEFAULT_MESSAGE, &block) click to toggle source
# File lib/git-ds/exec_cmd.rb, line 51
def initialize(index, nested, msg=DEFAULT_MESSAGE, &block)
  @index = index
  @database = index.repo
  @nested = nested
  @block = block
  # Default to no commit
  @commit_msg = msg
  # Default to config[user.name] and config[user.email]
  @commit_author = nil
end

Public Instance Methods

actor=(actor) click to toggle source

Set actor for commit.

# File lib/git-ds/exec_cmd.rb, line 80
def actor=(actor)
  @commit_author = actor
end
author(name, email) click to toggle source

Set the Git Author info for the commit. By default, this information is pulled from the Git config file.

# File lib/git-ds/exec_cmd.rb, line 73
def author(name, email)
  @commit_author = Grit::Actor.new(name, email)
end
commit() click to toggle source

Commit index.

# File lib/git-ds/exec_cmd.rb, line 87
def commit
  self.index.commit(@commit_msg, @commit_author)
end
message(str) click to toggle source

Set a commit message for this command.

# File lib/git-ds/exec_cmd.rb, line 65
def message(str)
  @commit_msg = str
end
perform() click to toggle source

Perform command.

# File lib/git-ds/exec_cmd.rb, line 94
def perform
  rv = instance_eval(&self.block)

  self.index.build
  if not self.nested
    commit
    @database.notify
  end

  rv
end