Class: GitDS::ExecCmd
- Inherits:
-
Object
- Object
- GitDS::ExecCmd
- Defined in:
- lib/git-ds/exec_cmd.rb
Overview
A command to be executed in a database context (i.e. an Index).
Usage:
db.exec { |idx| … }
See also Transaction.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_MESSAGE =
'auto-commit on transaction'
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
The body of the command.
-
#commit_author ⇒ Object
readonly
The Git author for the commit performed at the end of the command.
-
#commit_msg ⇒ Object
readonly
The message to use for the commit at the end of the command.
-
#database ⇒ Object
readonly
The GitDS::Database on which the command operates.
-
#index ⇒ Object
readonly
The GitDS::Index on which the command operates.
-
#nested ⇒ Object
readonly
Is command nested (inside a parent)? If true, a write and commit will not be performed.
Instance Method Summary collapse
-
#actor=(actor) ⇒ Object
Set actor for commit.
-
#author(name, email) ⇒ Object
Set the Git Author info for the commit.
-
#commit ⇒ Object
Commit index.
-
#initialize(index, nested, msg = DEFAULT_MESSAGE, &block) ⇒ ExecCmd
constructor
A new instance of ExecCmd.
-
#message(str) ⇒ Object
Set a commit message for this command.
-
#perform ⇒ Object
Perform command.
Constructor Details
#initialize(index, nested, msg = DEFAULT_MESSAGE, &block) ⇒ ExecCmd
Returns a new instance of ExecCmd.
51 52 53 54 55 56 57 58 59 60 |
# 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 |
Instance Attribute Details
#block ⇒ Object (readonly)
The body of the command.
44 45 46 |
# File 'lib/git-ds/exec_cmd.rb', line 44 def block @block end |
#commit_author ⇒ Object (readonly)
The Git author for the commit performed at the end of the command. See commit_msg.
40 41 42 |
# File 'lib/git-ds/exec_cmd.rb', line 40 def @commit_author end |
#commit_msg ⇒ Object (readonly)
The message to use for the commit at the end of the command.
34 35 36 |
# File 'lib/git-ds/exec_cmd.rb', line 34 def commit_msg @commit_msg end |
#database ⇒ Object (readonly)
The GitDS::Database on which the command operates. Useful for nesting.
30 31 32 |
# File 'lib/git-ds/exec_cmd.rb', line 30 def database @database end |
#index ⇒ Object (readonly)
The GitDS::Index on which the command operates.
26 27 28 |
# File 'lib/git-ds/exec_cmd.rb', line 26 def index @index end |
#nested ⇒ Object (readonly)
Is command nested (inside a parent)? If true, a write and commit will not be performed.
49 50 51 |
# File 'lib/git-ds/exec_cmd.rb', line 49 def nested @nested end |
Instance Method Details
#actor=(actor) ⇒ Object
Set actor for commit.
80 81 82 |
# File 'lib/git-ds/exec_cmd.rb', line 80 def actor=(actor) @commit_author = actor end |
#author(name, email) ⇒ Object
Set the Git Author info for the commit. By default, this information is pulled from the Git config file.
73 74 75 |
# File 'lib/git-ds/exec_cmd.rb', line 73 def (name, email) @commit_author = Grit::Actor.new(name, email) end |
#commit ⇒ Object
Commit index.
87 88 89 |
# File 'lib/git-ds/exec_cmd.rb', line 87 def commit self.index.commit(@commit_msg, @commit_author) end |
#message(str) ⇒ Object
Set a commit message for this command.
65 66 67 |
# File 'lib/git-ds/exec_cmd.rb', line 65 def (str) @commit_msg = str end |
#perform ⇒ Object
Perform command.
94 95 96 97 98 99 100 101 102 103 104 |
# 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 |