Class: RSpec::Terraspace::Project
- Inherits:
-
Object
- Object
- RSpec::Terraspace::Project
- Defined in:
- lib/rspec/terraspace/project.rb
Instance Method Summary collapse
-
#build_app_subfolder(list, type_dir) ⇒ Object
Inputs:.
- #build_dir ⇒ Object
- #build_modules ⇒ Object
- #build_project ⇒ Object
- #build_root ⇒ Object
- #build_stacks ⇒ Object
- #clean ⇒ Object
- #copy(src, dest) ⇒ Object
- #create ⇒ Object
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
- #remove_test_folder(dest) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
6 7 8 9 10 11 12 13 |
# File 'lib/rspec/terraspace/project.rb', line 6 def initialize(={}) @options = @name = [:name] || "demo" @modules = [:modules] @stacks = [:stacks] @remove_test_folder = [:remove_test_folder].nil? ? true : [:remove_test_folder] end |
Instance Method Details
#build_app_subfolder(list, type_dir) ⇒ Object
Inputs:
list: options[:modules] or options[:stacks]
type_dir: modules or stacks
The list argument can support a Hash or String value.
If provided a Hahs, it should be structured like so:
{vm: "app/modules/vm", network: "app/modules/network"}
This allows for finer-control to specify what modules and stacks to build
If provide a String, it should be a path to folder containing all modules or stacks. This provides less fine-grain control but is easier to use and shorter.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rspec/terraspace/project.rb', line 61 def build_app_subfolder(list, type_dir) case list when Hash list.each do |name, src| dest = "#{build_dir}/app/#{type_dir}/#{name}" copy(src, dest) remove_test_folder(dest) if @remove_test_folder end when String dest = "#{build_dir}/app/#{type_dir}" FileUtils.rm_rf(dest) FileUtils.cp_r(list, dest) else raise "modules option must be a Hash or String" end end |
#build_dir ⇒ Object
91 92 93 |
# File 'lib/rspec/terraspace/project.rb', line 91 def build_dir "#{build_root}/#{@name}" end |
#build_modules ⇒ Object
37 38 39 |
# File 'lib/rspec/terraspace/project.rb', line 37 def build_modules build_app_subfolder(@modules, "modules") end |
#build_project ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec/terraspace/project.rb', line 24 def build_project parent_dir = File.dirname(build_dir) FileUtils.mkdir_p(parent_dir) Dir.chdir(parent_dir) do project_name = File.basename(build_dir) ::Terraspace::CLI::New::Project.start([project_name]) end # TODO: terraspace new project --no-config option instead FileUtils.rm_f("#{build_dir}/config/backend.tf") FileUtils.rm_f("#{build_dir}/config/provider.tf") end |
#build_root ⇒ Object
95 96 97 |
# File 'lib/rspec/terraspace/project.rb', line 95 def build_root ENV['TS_RSPEC_BUILD_ROOT'] || "/tmp/terraspace/test-harnesses" end |
#build_stacks ⇒ Object
41 42 43 |
# File 'lib/rspec/terraspace/project.rb', line 41 def build_stacks build_app_subfolder(@stacks, "stacks") end |
#clean ⇒ Object
82 83 84 |
# File 'lib/rspec/terraspace/project.rb', line 82 def clean FileUtils.rm_rf(build_dir) end |
#copy(src, dest) ⇒ Object
86 87 88 89 |
# File 'lib/rspec/terraspace/project.rb', line 86 def copy(src, dest) FileUtils.mkdir_p(File.dirname(dest)) FileUtils.cp_r(src, dest) end |
#create ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/rspec/terraspace/project.rb', line 15 def create clean build_project build_modules build_stacks puts "Test harness built: #{build_dir}" build_dir end |
#remove_test_folder(dest) ⇒ Object
78 79 80 |
# File 'lib/rspec/terraspace/project.rb', line 78 def remove_test_folder(dest) FileUtils.rm_rf("#{dest}/test") end |