Sha256: 84fb1035b7d8169ab38aa8a3cc8ca0aaeeb8a5d5789ace28983eae4d2e53958b

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

class Object
  # Load custom helper methods from project
  def load_helper_files(dir, type: :blueprint)
    paths = Dir.glob("#{dir}/**/*.rb")
    paths.sort_by! { |p| p.size } # so namespaces are loaded first
    paths.each do |path|
      next unless File.file?(path)

      filename = if type == :project
                   path.sub(%r{.*/helpers/[a-zA-Z\-_]+/},'').sub('.rb','')
                 else # blueprint, configset
                   path.sub(%r{.*/helpers/},'').sub('.rb','')
                 end
      module_name = filename.camelize

      # Prepend a period so require works when 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)

      # Examples:
      #   project:
      #     path:        app/helpers/custom/custom_helper.rb
      #     module_name: CustomHelper
      #   blueprint:
      #     path:        app/blueprints/demo/helpers/outputs.rb
      #     module_name: Outputs
      require path
      self.class.send :include, module_name.constantize
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lono-8.0.0.pre.rc5 lib/lono/ext/core/object.rb
lono-8.0.0.pre.rc4 lib/lono/ext/core/object.rb
lono-8.0.0.pre.rc3 lib/lono/ext/core/object.rb