Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/terraspace/ext/core/module.rb
Instance Method Summary collapse
-
#include_modules(dir) ⇒ Object
Include all modules within the relative folder.
- #include_plugin_helpers ⇒ Object
- #include_project_level_helpers ⇒ Object
Instance Method Details
#include_modules(dir) ⇒ Object
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>'"
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/terraspace/ext/core/module.rb', line 13 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 |
#include_plugin_helpers ⇒ Object
42 43 44 45 46 |
# File 'lib/terraspace/ext/core/module.rb', line 42 def include_plugin_helpers Terraspace::Plugin.helper_classes.each do |klass| include klass # IE: TerraspacePluginAws::Interfaces::Helper end end |
#include_project_level_helpers ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/terraspace/ext/core/module.rb', line 32 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 |