Class: GemNewgem::Newgem::Template

Inherits:
Object
  • Object
show all
Extended by:
Gem::UserInteraction
Defined in:
lib/gem_newgem/newgem/template.rb,
lib/gem_newgem/newgem/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Template

Returns a new instance of Template.



58
59
60
61
# File 'lib/gem_newgem/newgem/template.rb', line 58

def initialize(name)
  @name = name
  @config = Template.get_config
end

Instance Attribute Details

#nameObject (readonly)

Instance methods



56
57
58
# File 'lib/gem_newgem/newgem/template.rb', line 56

def name
  @name
end

Class Method Details

.create_base_dirObject



26
27
28
# File 'lib/gem_newgem/newgem/template.rb', line 26

def create_base_dir
  FileUtils.mkdir_p @config.templates_base_dir
end

.create_default_templateObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/gem_newgem/newgem/template.rb', line 34

def create_default_template
  alert "Default template doesn't seem to exists yet. Will git clone it now..."
  command = "git clone -v #{get_config.default_template_git_url} #{default_template_path}"
  say command
  result = system(command)
  alert_error "git not installed or not found in path." if result.nil?
  alert_error "Cloning default template failed." if $?.exitstatus != 0
  terminate_interaction(1) if $?.exitstatus != 0
  validate_exists(default_template_path)
end

.default_template_pathObject



30
31
32
# File 'lib/gem_newgem/newgem/template.rb', line 30

def default_template_path
  File.expand_path(File.join(get_config.templates_base_dir, get_config.default_template))
end

.ensure_defaultObject



21
22
23
24
# File 'lib/gem_newgem/newgem/template.rb', line 21

def ensure_default
  create_base_dir unless Dir.exists?(get_config.templates_base_dir)
  create_default_template unless Dir.exists?(default_template_path)
end

.get_configObject



17
18
19
# File 'lib/gem_newgem/newgem/template.rb', line 17

def get_config
  @config ||= GemNewgem::Newgem::Configuration.instance
end

.validate_exists(path) ⇒ Object



45
46
47
48
49
50
# File 'lib/gem_newgem/newgem/template.rb', line 45

def validate_exists(path)
  unless Dir.exists?(path)
    alert_error "Templates directory #{path} doesn't exist!"
    terminate_interaction(1)
  end
end

Instance Method Details

#pathObject



63
64
65
# File 'lib/gem_newgem/newgem/template.rb', line 63

def path
  File.expand_path(File.join(@config.templates_base_dir, name))
end

#validateObject



67
68
69
# File 'lib/gem_newgem/newgem/template.rb', line 67

def validate
  Template.validate_exists(path)
end