Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/sweetloader.rb

Instance Method Summary collapse

Instance Method Details

#autoload_modules(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sweetloader.rb', line 14

def autoload_modules *args

  options = args.extract_options!
  root = options[:root] || AutoLoader.root || ''
  path = root.strip.empty? ? self.name.to_s.underscore : [root, self.name.to_s.underscore].join('/')
  from = options[:from] || path

  # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
  # It is very useful for situations of having not load_paths built Rails or Gems way.
  args.each do |req_name|
    ruby_file = req_name.to_s.underscore

    send :autoload, req_name, AutoLoader.translate("#{from}/#{ruby_file}")
  end
end

#include_and_extend(the_module, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/sweetloader.rb', line 4

def include_and_extend(the_module, options={})
  options[:instance_methods] ||= :InstanceMethods
  options[:class_methods] ||= :ClassMethods
  # Mainly include but be flexible
  main_module = const_get(the_module.to_s.to_sym)
  include main_module # for an extend_and_include method, change this to extend main_module
  include main_module.const_get(options[:instance_methods]) if main_module.const_defined?(options[:instance_methods])
  extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods])
end