Class: GemNewgem::Newgem::Template
- Inherits:
-
Object
- Object
- GemNewgem::Newgem::Template
- Extended by:
- Gem::UserInteraction
- Defined in:
- lib/gem_newgem/newgem/template.rb,
lib/gem_newgem/newgem/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Instance methods.
Class Method Summary collapse
- .create_base_dir ⇒ Object
- .create_default_template ⇒ Object
- .default_template_path ⇒ Object
- .ensure_default ⇒ Object
- .get_config ⇒ Object
- .validate_exists(path) ⇒ Object
Instance Method Summary collapse
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #path ⇒ Object
- #validate ⇒ Object
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
#name ⇒ Object (readonly)
Instance methods
56 57 58 |
# File 'lib/gem_newgem/newgem/template.rb', line 56 def name @name end |
Class Method Details
.create_base_dir ⇒ Object
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_template ⇒ Object
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_path ⇒ Object
30 31 32 |
# File 'lib/gem_newgem/newgem/template.rb', line 30 def default_template_path File.(File.join(get_config.templates_base_dir, get_config.default_template)) end |
.ensure_default ⇒ Object
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_config ⇒ Object
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
#path ⇒ Object
63 64 65 |
# File 'lib/gem_newgem/newgem/template.rb', line 63 def path File.(File.join(@config.templates_base_dir, name)) end |
#validate ⇒ Object
67 68 69 |
# File 'lib/gem_newgem/newgem/template.rb', line 67 def validate Template.validate_exists(path) end |