Class: Stevenson::Template::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/stevenson/templates/git.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#close, #place_config, #place_files

Constructor Details

#initialize(template_url, options) ⇒ Git

Returns a new instance of Git.



8
9
10
# File 'lib/stevenson/templates/git.rb', line 8

def initialize(template_url, options)
  @template_url, @options = template_url, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/stevenson/templates/git.rb', line 6

def options
  @options
end

#template_urlObject (readonly)

Returns the value of attribute template_url.



6
7
8
# File 'lib/stevenson/templates/git.rb', line 6

def template_url
  @template_url
end

Instance Method Details

#local_directoryObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/stevenson/templates/git.rb', line 12

def local_directory
  @_local_directory ||= Dir.mktmpdir.tap do |dir|
    # Clone the repo to a temporary directory for later use
    ::Git.clone(template_url, dir).tap do |repo|
      # Switch_branch if set
      repo.checkout(options[:branch]) if options.has_key?(:branch)
    end
  end
rescue ::Git::GitExecuteError
  # If the given repo URL is not valid, raise an exception
  raise InvalidTemplateException.new('Failed to clone the repository')
end