Class: Rosette::Core::Commands::SnapshotCommand

Inherits:
GitCommand show all
Includes:
WithRef, WithRepoName, WithSnapshots
Defined in:
lib/rosette/core/commands/git/snapshot_command.rb

Overview

Takes a snapshot and returns a list of phrases. This is different from RepoSnapshotCommand in that it doesn't return the snapshot hash itself, but instead the phrases contained in the snapshot's commits.

Examples:

cmd = SnapshotCommand.new(configuration)
  .set_repo_name('my_repo')
  .set_ref('master')

cmd.execute
# => [<Phrase #ba012cd key: 'foobar'>, ...]

Instance Attribute Summary collapse

Attributes included from WithRef

#commit_str

Attributes included from WithRepoName

#repo_name

Attributes inherited from Command

#configuration

Instance Method Summary collapse

Methods included from WithRef

#commit_id, #set_commit_id, #set_ref

Methods included from WithRepoName

#set_repo_name

Methods included from WithSnapshots

#take_snapshot

Methods inherited from GitCommand

#valid?

Methods inherited from Command

#initialize, #messages, #valid?, validate, validators

Constructor Details

This class inherits a constructor from Rosette::Core::Commands::Command

Instance Attribute Details

#pathsArray (readonly)

Returns the paths to consider when taking the snapshot. Any paths that do not exist in this array will not appear in the snapshot.

Returns:

  • (Array)

    the paths to consider when taking the snapshot. Any paths that do not exist in this array will not appear in the snapshot.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rosette/core/commands/git/snapshot_command.rb', line 22

class SnapshotCommand < GitCommand
  attr_reader :paths

  include WithSnapshots
  include WithRepoName
  include WithRef

  # Set the paths that will be included in the snapshot.
  #
  # @param [Array] paths The paths to include in the snapshot.
  # @return [self]
  def set_paths(paths)
    @paths = paths
    self
  end

  # Take the snapshot.
  #
  # @return [Array<Rosette::Core::Phrase>] the list of phrases from the
  #   snapshot.
  def execute
    snapshot = take_snapshot(get_repo(repo_name), commit_id, paths)
    datastore.phrases_by_commits(repo_name, snapshot).to_a
  end
end

Instance Method Details

#executeArray<Rosette::Core::Phrase>

Take the snapshot.

Returns:


42
43
44
45
# File 'lib/rosette/core/commands/git/snapshot_command.rb', line 42

def execute
  snapshot = take_snapshot(get_repo(repo_name), commit_id, paths)
  datastore.phrases_by_commits(repo_name, snapshot).to_a
end

#set_paths(paths) ⇒ self

Set the paths that will be included in the snapshot.

Parameters:

  • paths (Array)

    The paths to include in the snapshot.

Returns:

  • (self)

33
34
35
36
# File 'lib/rosette/core/commands/git/snapshot_command.rb', line 33

def set_paths(paths)
  @paths = paths
  self
end