Sha256: 2397c737f275aa46ad8398d0d8936a53ae940efa08035adad02814ea88b33c65

Contents?: true

Size: 1005 Bytes

Versions: 29

Compression:

Stored size: 1005 Bytes

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/lono-1.1.1/lib/lono/builder.rb:34:in `build'"
  #   linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/lono-1.1.1/lib/lono/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
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
lono-8.0.0.pre.rc6 lib/lono/ext/core/module.rb
lono-8.0.0.pre.rc5 lib/lono/ext/core/module.rb
ufo-6.3.2 lib/ufo/ext/core/module.rb
ufo-6.3.1 lib/ufo/ext/core/module.rb
ufo-6.3.0 lib/ufo/ext/core/module.rb
ufo-6.2.5 lib/ufo/ext/core/module.rb
ufo-6.2.4 lib/ufo/ext/core/module.rb
ufo-6.2.3 lib/ufo/ext/core/module.rb
ufo-6.2.2 lib/ufo/ext/core/module.rb
lono-8.0.0.pre.rc4 lib/lono/ext/core/module.rb
ufo-6.2.1 lib/ufo/ext/core/module.rb
ufo-6.2.0 lib/ufo/ext/core/module.rb
ufo-6.1.5 lib/ufo/ext/core/module.rb
ufo-6.1.4 lib/ufo/ext/core/module.rb
ufo-6.1.3 lib/ufo/ext/core/module.rb
ufo-6.1.2 lib/ufo/ext/core/module.rb
ufo-6.1.1 lib/ufo/ext/core/module.rb
ufo-6.1.0 lib/ufo/ext/core/module.rb
ufo-6.0.9 lib/ufo/ext/core/module.rb
ufo-6.0.8 lib/ufo/ext/core/module.rb