Sha256: 8f67cff5cc37b4e4e5a15d3bf3119b2e49333351e212fcfba1ec643702bf9e42

Contents?: true

Size: 1.49 KB

Versions: 30

Compression:

Stored size: 1.49 KB

Contents

class Module
  # Include all modules within the relative folder. IE: for dsl/syntax/mod/*
  #
  #    include Common
  #    include Provider
  #    # etc
  #
  # Caller lines are different for OSes:
  #
  #   windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace-1.1.1/lib/terraspace/builder.rb:34:in `build'"
  #   linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/terraspace-1.1.1/lib/terraspace/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
  #
  def include_modules(dir)
    caller_line = caller[0]
    parts = caller_line.split(':')
    calling_file = caller_line.match(/^[a-zA-Z]:/) ? parts[1] : parts[0]
    parent_dir = File.dirname(calling_file)

    full_dir = "#{parent_dir}/#{dir}"
    paths = Dir.glob("#{full_dir}/**/*.rb")
    if paths.empty?
      raise "Empty include_modules full_dir: #{full_dir}"
    end
    paths.each do |path|
      regexp = Regexp.new(".*/lib/")
      mod = path.sub(regexp, '').sub('.rb','').camelize
      c = mod.constantize
      include c if c.class == Module
    end
  end

  def include_project_level_helpers
    full_dir = "#{Terraspace.root}/config/helpers"
    Dir.glob("#{full_dir}/**/*").each do |path|
      regexp = Regexp.new(".*/config/helpers/")
      klass = path.sub(regexp, '').sub('.rb','').camelize
      klass = "Terraspace::Project::#{klass}"
      include klass.constantize
    end
  end

  def include_plugin_helpers
    Terraspace::Plugin.helper_classes.each do |klass|
      include klass # IE: TerraspacePluginAws::Interfaces::Helper
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/ext/core/module.rb
terraspace-2.2.16 lib/terraspace/ext/core/module.rb
terraspace-2.2.15 lib/terraspace/ext/core/module.rb
terraspace-2.2.14 lib/terraspace/ext/core/module.rb
terraspace-2.2.13 lib/terraspace/ext/core/module.rb
terraspace-2.2.12 lib/terraspace/ext/core/module.rb
terraspace-2.2.11 lib/terraspace/ext/core/module.rb
terraspace-2.2.10 lib/terraspace/ext/core/module.rb
terraspace-2.2.9 lib/terraspace/ext/core/module.rb
terraspace-2.2.8 lib/terraspace/ext/core/module.rb
terraspace-2.2.7 lib/terraspace/ext/core/module.rb
terraspace-2.2.6 lib/terraspace/ext/core/module.rb
terraspace-2.2.5 lib/terraspace/ext/core/module.rb
terraspace-2.2.4 lib/terraspace/ext/core/module.rb
terraspace-2.2.3 lib/terraspace/ext/core/module.rb
terraspace-2.2.2 lib/terraspace/ext/core/module.rb
terraspace-2.2.1 lib/terraspace/ext/core/module.rb
terraspace-2.2.0 lib/terraspace/ext/core/module.rb
terraspace-2.1.7 lib/terraspace/ext/core/module.rb
terraspace-2.1.6 lib/terraspace/ext/core/module.rb