Sha256: a23fba010f72b952c84e86aae3af8a13e4c2043b38e7a4a5164144e4de09a560

Contents?: true

Size: 817 Bytes

Versions: 22

Compression:

Stored size: 817 Bytes

Contents

module Lono::Template::Context::Loader
  module LoadFiles
    # Load custom helper methods from project
    def load_files(root)
      paths = Dir.glob("#{root}/**/*.rb")
      paths.sort_by! { |p| p.size } # so namespaces are loaded first
      paths.each do |path|
        # lib = gem extensions
        # app = project extensions
        filename = path.sub(%r{.*/lib/},'').sub(%r{.*/app/helpers/},'').sub('.rb','')
        module_name = filename.camelize

        # Prepend a period so require works LONO_ROOT is set to a relative path without a period.
        #
        # Example: LONO_ROOT=tmp/lono_project
        first_char = path[0..0]
        path = "./#{path}" unless %w[. /].include?(first_char)

        require path
        self.class.send :include, module_name.constantize
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lono-7.5.2 lib/lono/template/context/loader/load_files.rb
lono-7.5.1 lib/lono/template/context/loader/load_files.rb
lono-7.5.0 lib/lono/template/context/loader/load_files.rb
lono-7.4.11 lib/lono/template/context/loader/load_files.rb
lono-7.4.10 lib/lono/template/context/loader/load_files.rb
lono-7.4.9 lib/lono/template/context/loader/load_files.rb
lono-7.4.8 lib/lono/template/context/loader/load_files.rb
lono-7.4.7 lib/lono/template/context/loader/load_files.rb
lono-7.4.6 lib/lono/template/context/loader/load_files.rb
lono-7.4.5 lib/lono/template/context/loader/load_files.rb
lono-7.4.4 lib/lono/template/context/loader/load_files.rb
lono-7.4.3 lib/lono/template/context/loader/load_files.rb
lono-7.4.2 lib/lono/template/context/loader/load_files.rb
lono-7.4.1 lib/lono/template/context/loader/load_files.rb
lono-7.4.0 lib/lono/template/context/loader/load_files.rb
lono-7.3.2 lib/lono/template/context/loader/load_files.rb
lono-7.3.1 lib/lono/template/context/loader/load_files.rb
lono-7.3.0 lib/lono/template/context/loader/load_files.rb
lono-7.2.3 lib/lono/template/context/loader/load_files.rb
lono-7.2.2 lib/lono/template/context/loader/load_files.rb