Class: Stevenson::Template::Git

Inherits:
Local show all
Defined in:
lib/stevenson/templates/git.rb

Instance Attribute Summary collapse

Attributes inherited from Local

#template_path

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#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

#closeObject



29
30
31
32
# File 'lib/stevenson/templates/git.rb', line 29

def close
  FileUtils.rm_rf template_path if template_path
  super
end

#local_directoryObject



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

def local_directory
  @_local_directory ||= begin
    @template_path ||= 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

    super
  end
rescue ::Git::GitExecuteError
  # If the given repo URL is not valid, raise an exception
  raise InvalidTemplateException.new('Failed to clone the repository and/or branch')
end