Class: TerraspaceBundler::Exporter::Stacks::Stack
- Defined in:
- lib/terraspace_bundler/exporter/stacks/stack.rb
Instance Attribute Summary collapse
-
#mod ⇒ Object
readonly
Returns the value of attribute mod.
Instance Method Summary collapse
- #copy ⇒ Object
- #dest ⇒ Object
- #examples ⇒ Object
-
#examples_folder ⇒ Object
public method used by StackConcern#all_stacks.
- #export ⇒ Object
-
#initialize(mod, options = {}) ⇒ Stack
constructor
A new instance of Stack.
- #pretty_path(path) ⇒ Object
-
#purge? ⇒ Boolean
purge precedence:.
- #rewrite ⇒ Object
- #src ⇒ Object
Constructor Details
#initialize(mod, options = {}) ⇒ Stack
Returns a new instance of Stack.
4 5 6 7 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 4 def initialize(mod, ={}) @mod, @options = mod, @src = @options[:src] || @options[:example] || @options[:name] end |
Instance Attribute Details
#mod ⇒ Object (readonly)
Returns the value of attribute mod.
3 4 5 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 3 def mod @mod end |
Instance Method Details
#copy ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 14 def copy return unless @options FileUtils.rm_rf(dest) if purge? return if File.exist?(dest) FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp_r(src, dest) end |
#dest ⇒ Object
59 60 61 62 63 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 59 def dest dest = @options[:dest] || TB.config.[:dest] name = @options[:name] || @mod.name # falls back to mod name by default "#{dest}/#{name}" end |
#examples ⇒ Object
55 56 57 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 55 def examples @options[:examples] || TB.config.[:examples] end |
#examples_folder ⇒ Object
public method used by StackConcern#all_stacks
51 52 53 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 51 def examples_folder [mod_path, examples].join('/') end |
#export ⇒ Object
9 10 11 12 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 9 def export copy rewrite end |
#pretty_path(path) ⇒ Object
46 47 48 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 46 def pretty_path(path) path.sub("#{Dir.pwd}/",'') end |
#purge? ⇒ Boolean
purge precedence:
1. Terrafile mod level stack option
2. Terrafile-level stack_options
70 71 72 73 74 75 76 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 70 def purge? # config.stack_options is set from Terrafile-level stack_options to TB.config.stack # relevant source code: dsl/syntax.rb: def stack_options config = TB.config.[:purge] config = config.nil? ? false : config @options[:purge].nil? ? config : @options[:purge] end |
#rewrite ⇒ Object
24 25 26 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 24 def rewrite Rewrite.new(self).run end |
#src ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/terraspace_bundler/exporter/stacks/stack.rb', line 28 def src src = @src without_examples = [mod_path, src].compact.join('/') with_examples = [examples_folder, src].compact.join('/') paths = [with_examples, without_examples] found = paths.find do |path| File.exist?(path) end unless found searched = paths.map { |p| pretty_path(p) }.map { |p| " #{p}" }.join("\n") logger.error "ERROR: Example not found. stack src: #{src}. Searched:".color(:red) logger.error searched exit 1 end found end |