Sha256: e1c61381d440b6dab84db03e3e1807646e37d5f4f459510e550a7e247c97e314
Contents?: true
Size: 996 Bytes
Versions: 16
Compression:
Stored size: 996 Bytes
Contents
module Terraspace::Compiler module HelperExtender private def extend_module_level_helpers full_dir = "#{@mod.root}/config/helpers" Dir.glob("#{full_dir}/**/*").each do |path| regexp = Regexp.new(".*/helpers/") klass = path.sub(regexp, '').sub('.rb','').camelize klass = "#{mod_namespace}::#{klass}" require path # able to use require instead of load since each helper has unique namespace send :extend, klass.constantize end end # IE: mod_namespace = Terraspace::Module::Demo # Use separate namespaces scope with module name so custom helper methods from different modules are isolated. def mod_namespace mod_name = @mod.name.camelize ns = "Terraspace::#{@mod.type.camelize}".constantize # IE: Terraspace::Module or Terraspace::Stack if ns.const_defined?(mod_name.to_sym) "#{ns}::#{mod_name}".constantize else ns.const_set(mod_name, Module.new) end end end end
Version data entries
16 entries across 16 versions & 1 rubygems