Module: Rosette::Core::Commands::WithRepoName

Overview

Mixin that handles configuration and validation of a repository name. Meant to be mixed into the classes in Rosette::Core::Commands.

Examples:

class MyCommand < Rosette::Core::Commands::Command
  include WithRepoName
end

cmd = MyCommand.new
  .set_repo_name('my_repo')

cmd.repo_name  # => "my_repo"
cmd.valid?     # => true

cmd.set_repo_name('non_existent_repo')
cmd.valid?     # => false
cmd.messages   # => { repo_name: ["Unable to find repo 'non_existent_repo'."] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repo_nameString (readonly)

Returns the repository name.

Returns:

  • (String)

    the repository name.


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/with_repo_name.rb', line 27

module WithRepoName
  attr_reader :repo_name

  # Set the repository name.
  #
  # @param [String] repo_name The repository name.
  # @return [self]
  def set_repo_name(repo_name)
    @repo_name = repo_name
    self
  end

  protected

  def self.included(base)
    if base.respond_to?(:validate)
      base.validate :repo_name, type: :repo
    end
  end
end

Instance Method Details

#set_repo_name(repo_name) ⇒ self

Set the repository name.

Parameters:

  • repo_name (String)

    The repository name.

Returns:

  • (self)

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

def set_repo_name(repo_name)
  @repo_name = repo_name
  self
end