Module: SweetLoader
Defined Under Namespace
Classes: Scope
Instance Method Summary collapse
- #autoload_modules(*args) ⇒ Object (also: #autoload_module)
- #autoload_scope(options = {}, &block) ⇒ Object
- #include_and_extend(the_module, options = {}) ⇒ Object
Instance Method Details
#autoload_modules(*args) ⇒ Object Also known as: autoload_module
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sweetloader.rb', line 15 def autoload_modules *args = args. .merge!() if respond_to? :autoload_options root = [:root] || AutoLoader.root || '' path = root.strip.empty? ? self.name.to_s.underscore : [root, self.name.to_s.underscore].join('/') from = [:from] || path proc = [:mutate_path] from = proc.call(from) if proc the_module = send(:the_module) if respond_to? :the_module the_module ||= self # 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 require_file = AutoLoader.translate("#{from}/#{ruby_file}", ) the_module.send :autoload, req_name, require_file end end |
#autoload_scope(options = {}, &block) ⇒ Object
38 39 40 41 42 |
# File 'lib/sweetloader.rb', line 38 def autoload_scope = {}, &block if block_given? block.arity == 1 ? yield(self) : SweetLoader::Scope.new(self, ).instance_eval(&block) end end |
#include_and_extend(the_module, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/sweetloader.rb', line 5 def include_and_extend(the_module, ={}) [:instance_methods] ||= :InstanceMethods [: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([:instance_methods]) if main_module.const_defined?([:instance_methods]) extend main_module.const_get([:class_methods]) if main_module.const_defined?([:class_methods]) end |