Method: Terraspace::Mod#cache_dir

Defined in:
lib/terraspace/mod.rb

#cache_dir(options = {}) ⇒ Object

Full path with build_dir



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/terraspace/mod.rb', line 114

def cache_dir(options={})
  # config.build.cache_dir is a String or object that respond_to call. IE:
  #   :REGION/:ENV/:BUILD_DIR
  #   CustomBuildDir.call
  # The call method should return a String pattern used for substitutions
  object = Terraspace.config.build.cache_dir
  pattern = if object.is_a?(String)
      object
    elsif object.respond_to?(:call)
      object.call(self)
    elsif object.public_instance_methods.include?(:call)
      instance = object.new
      instance.call(self)
    else
      raise "ERROR: config.build.cache_dir is not a String or responds to the .call method."
    end

  if pattern.include?(":CACHE_ROOT")
    old_pattern = pattern
    pattern = pattern.sub(':CACHE_ROOT/', '')
    logger.info "WARN: Detected :CACHE_ROOT in config.build.cache_dir".color(:yellow)
    logger.info <<~EOL
      This has been deprecated and :CACHE_ROOT should not be in the config.build.cache_dir setting.
      The :CACHE_ROOT pattern has been removed from config.build.cache_dir automatically.

      To remove this warning, remove the :CACHE_ROOT. For example:

      config/app.rb

          config.build.cache_dir = "#{old_pattern}"

      Update it to:

          config.build.cache_dir = "#{pattern}"

    EOL
  end

  path = expansion(pattern)
  path = "#{Terraspace.cache_root}/#{path}"
  path.gsub!(%r{/+},'/') # remove double slashes are more. IE: // -> / Useful since region is '' in generic expander
  path
end