Module: TerraspaceBundler::Mod::Concerns::PathConcern
- Defined in:
- lib/terraspace_bundler/mod/concerns/path_concern.rb
Instance Method Summary collapse
- #cache_path(name) ⇒ Object
- #cache_root ⇒ Object
- #get_bucket_key(path) ⇒ Object
- #get_mod_path(mod) ⇒ Object
- #mod_path ⇒ Object
-
#rel_dest_dir ⇒ Object
Fetcher: Downloader/Local copies to a slightly different folder.
- #remove_ext(path) ⇒ Object
- #setup_tmp ⇒ Object
- #stage_path(name) ⇒ Object
- #stage_root ⇒ Object
- #tmp_root ⇒ Object
- #type_path ⇒ Object
Instance Method Details
#cache_path(name) ⇒ Object
20 21 22 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 20 def cache_path(name) [cache_root, @mod.type, name].compact.join('/') end |
#cache_root ⇒ Object
12 13 14 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 12 def cache_root "#{tmp_root}/cache" end |
#get_bucket_key(path) ⇒ Object
62 63 64 65 66 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 62 def get_bucket_key(path) bucket, *rest = path.split('/') key = rest.join('/') [bucket, key] end |
#get_mod_path(mod) ⇒ Object
72 73 74 75 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 72 def get_mod_path(mod) export_to = mod.export_to || TB.config.export_to "#{export_to}/#{mod.name}" end |
#mod_path ⇒ Object
68 69 70 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 68 def mod_path get_mod_path(@mod) end |
#rel_dest_dir ⇒ Object
Fetcher: Downloader/Local copies to a slightly different folder. Also, Copy will use this and reference same method so it’s consistent.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 30 def rel_dest_dir case @mod.type when 'local' @mod.name # example-module when 's3' path = type_path # https://s3-us-west-2.amazonaws.com/demo-terraform-test/example-module.zip remove_ext(path) # demo-terraform-test/modules/example-module when 'gcs' path = type_path # https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip path.sub!(%r{storage/v\d+/},'') remove_ext(path) # terraform-example-modules/modules/example-module when 'http' path = type_path # https://www.googleapis.com/storage/v1/BUCKET_NAME/PATH/TO/module.zip remove_ext(path) # terraform-example-modules/modules/example-module else # inferred git, registry, git::, ssh://, git::ssh:// @mod.repo_folder # tongueroo/example-module end end |
#remove_ext(path) ⇒ Object
57 58 59 60 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 57 def remove_ext(path) ext = File.extname(path) path.sub(ext,'') end |
#setup_tmp ⇒ Object
3 4 5 6 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 3 def setup_tmp FileUtils.mkdir_p(cache_root) FileUtils.mkdir_p(stage_root) end |
#stage_path(name) ⇒ Object
24 25 26 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 24 def stage_path(name) [stage_root, @mod.type, name].compact.join('/') end |
#stage_root ⇒ Object
16 17 18 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 16 def stage_root "#{tmp_root}/stage" end |
#tmp_root ⇒ Object
8 9 10 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 8 def tmp_root "/tmp/terraspace/bundler" end |
#type_path ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/terraspace_bundler/mod/concerns/path_concern.rb', line 49 def type_path source = @mod.source url = source.sub("#{@mod.type}::",'') uri = URI(url) uri.path.sub('/','') # removing leading slash to bucket name is the first thing .sub(%r{//(.*)},'') # remove subfolder end |