Class: Terraspace::CLI::New::Source::Core
- Inherits:
-
Object
- Object
- Terraspace::CLI::New::Source::Core
show all
- Includes:
- Helpers::PluginGem, Util
- Defined in:
- lib/terraspace/cli/new/source/core.rb
Instance Method Summary
collapse
#pretty_path, #pretty_time
Methods included from Util::Sure
#sure?
#logger
Constructor Details
#initialize(sequence, options) ⇒ Core
Returns a new instance of Core.
6
7
8
|
# File 'lib/terraspace/cli/new/source/core.rb', line 6
def initialize(sequence, options)
@sequence, @options = sequence, options
end
|
Instance Method Details
#override_source_paths(*paths) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/terraspace/cli/new/source/core.rb', line 53
def override_source_paths(*paths)
@sequence.instance_variable_set(:@source_paths, nil) @sequence.class.instance_eval %{
def self.source_paths
#{paths.flatten.inspect}
end
}
end
|
#require_gem(name) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/terraspace/cli/new/source/core.rb', line 21
def require_gem(name)
return unless name begin
Gem.clear_paths
require name rescue LoadError => e
puts "#{e.class}: #{e.message}".color(:red)
logger.error "ERROR: Unable to require plugin #{name}".color(:red)
puts "Are you sure you the plugin exists and you specified the right plugin option."
puts "You specified --plugin #{@options[:plugin]}"
exit 1
end
end
|
#set_core_source(template, type = nil) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/terraspace/cli/new/source/core.rb', line 10
def set_core_source(template, type=nil)
template_name = template_name(template, type)
folder = @options[:examples] && type != "project" ? "examples/#{template_name}" : template_name
template_path = File.expand_path("../../../../templates/#{folder}", __dir__)
override_source_paths(template_path)
end
|
#set_plugin_gem_source(template, type) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/terraspace/cli/new/source/core.rb', line 36
def set_plugin_gem_source(template, type)
require_gem(plugin_gem_name)
plugin = Terraspace::Plugin.find_with(plugin: @options[:plugin])
return unless plugin template_name = template_name(template, type)
template_path = File.expand_path("#{plugin.root}/lib/templates/#{template_name}")
override_source_paths(template_path)
end
|
#template_name(template, type) ⇒ Object
17
18
19
|
# File 'lib/terraspace/cli/new/source/core.rb', line 17
def template_name(template, type=nil)
[template, type].compact.join('/')
end
|