Class: Terraspace::CLI::New::Source::Core
- Inherits:
-
Object
- Object
- Terraspace::CLI::New::Source::Core
- Includes:
- Helper::PluginGem, Util
- Defined in:
- lib/terraspace/cli/new/source/core.rb
Instance Method Summary collapse
-
#initialize(sequence, options) ⇒ Core
constructor
A new instance of Core.
- #override_source_paths(*paths) ⇒ Object
- #require_gem(name) ⇒ Object
- #set_core_source(template, type = nil) ⇒ Object
- #set_plugin_gem_source(template, type) ⇒ Object
- #template_name(template, type) ⇒ Object
Methods included from Util
Methods included from Util::Sure
Methods included from Util::Sh
Methods included from Util::Logging
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, ) @sequence, @options = sequence, end |
Instance Method Details
#override_source_paths(*paths) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/terraspace/cli/new/source/core.rb', line 52 def override_source_paths(*paths) # https://github.com/erikhuda/thor/blob/34df888d721ecaa8cf0cea97d51dc6c388002742/lib/thor/actions.rb#L128 @sequence.instance_variable_set(:@source_paths, nil) # unset instance variable cache # Using string with instance_eval because block doesnt have access to path at runtime. @sequence.class.instance_eval %{ def self.source_paths #{paths.flatten.inspect} end } end |
#require_gem(name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/terraspace/cli/new/source/core.rb', line 20 def require_gem(name) begin require name # require plugin for the templates, this registers the plugin rescue LoadError => e puts "#{e.class}: #{e.}".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 |
# File 'lib/terraspace/cli/new/source/core.rb', line 10 def set_core_source(template, type=nil) template_name = template_name(template, type) template_path = File.("../../../../templates/#{template_name}", __dir__) override_source_paths(template_path) end |
#set_plugin_gem_source(template, type) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/terraspace/cli/new/source/core.rb', line 32 def set_plugin_gem_source(template, type) require_gem(plugin_gem_name) plugin = Terraspace::Plugin.find_with(plugin: @options[:plugin]) unless plugin puts "ERROR: Unable to a find plugin for #{@options[:plugin]}. Are you sure the gem for the plugin is correct?".color(:red) exit 1 end template_name = template_name(template, type) template_path = File.("#{plugin.root}/lib/templates/#{template_name}") override_source_paths(template_path) end |
#template_name(template, type) ⇒ Object
16 17 18 |
# File 'lib/terraspace/cli/new/source/core.rb', line 16 def template_name(template, type=nil) [template, type].compact.join('/') end |