Skip to content

Commit

Permalink
Fixed #104
Browse files Browse the repository at this point in the history
  • Loading branch information
Beniamin Sarkisyan committed Apr 11, 2016
1 parent bd6d67f commit 112d0b3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/generamba/constants/rambafile_constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ module Generamba
TEMPLATE_DECLARATION_NAME_KEY = 'name'
TEMPLATE_DECLARATION_LOCAL_KEY = 'local'
TEMPLATE_DECLARATION_GIT_KEY = 'git'
TEMPLATE_DECLARATION_BRANCH_KEY = 'branch'
end
3 changes: 1 addition & 2 deletions lib/generamba/template/helpers/rambaspec_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def self.validate_spec(template_name, template_path)
# @return [Bool]
def self.obtain_spec_path(template_name, template_path)
spec_filename = template_name + RAMBASPEC_EXTENSION
Pathname.new(template_path)
.join(spec_filename)
Pathname.new(template_path).join(spec_filename)
end
end
end
19 changes: 13 additions & 6 deletions lib/generamba/template/installer/remote_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ def install_template(template_declaration)
puts("Installing #{template_name}...")

repo_url = template_declaration.git
repo_branch = template_declaration.branch

temp_path = Dir.tmpdir()
template_dir = Pathname.new(temp_path)
.join(template_name)
Git.clone(repo_url, template_name, :path => temp_path)
template_dir = Pathname.new(temp_path).join(template_name)

if repo_branch != nil
Git.export(repo_url, template_name, :branch => repo_branch, :path => temp_path)
else
Git.clone(repo_url, template_name, :path => temp_path)
end

template_path = "#{template_dir}/#{template_name}"

rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_dir)
rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_path)
unless rambaspec_exist
FileUtils.rm_rf(temp_path)
error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the root directory of specified repository.".red
raise StandardError.new(error_description)
end

rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_dir)
rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_path)
unless rambaspec_valid
error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
raise StandardError.new(error_description)
Expand All @@ -35,7 +42,7 @@ def install_template(template_declaration)
install_path = Pathname.new(TEMPLATES_FOLDER)
.join(template_name)
FileUtils.mkdir_p install_path
FileUtils.copy_entry(template_dir, install_path)
FileUtils.copy_entry(template_path, install_path)

FileUtils.rm_rf(temp_path)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/generamba/template/processor/template_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class TemplateDeclarationType
# Describes a Generamba template declaration model
class TemplateDeclaration

attr_reader :name, :local, :git, :type
attr_reader :name, :local, :git, :branch, :type

def initialize(template_hash)
@name = template_hash[TEMPLATE_DECLARATION_NAME_KEY]
@local = template_hash[TEMPLATE_DECLARATION_LOCAL_KEY]
@git = template_hash[TEMPLATE_DECLARATION_GIT_KEY]
@branch = template_hash[TEMPLATE_DECLARATION_BRANCH_KEY]

@type = TemplateDeclarationType::LOCAL_TEMPLATE if @local
@type = TemplateDeclarationType::REMOTE_TEMPLATE if @git
Expand Down

0 comments on commit 112d0b3

Please sign in to comment.