module Modulation::ModuleMixin
Extension methods for loaded modules
Constants
- EXPORT_DEFAULT_ERROR_MSG
Attributes
__export_default_info[R]
__module_info[RW]
read and write module information
Public Instance Methods
__add_dependency(mod)
click to toggle source
# File lib/modulation/module_mixin.rb, line 110 def __add_dependency(mod) __dependencies << mod unless __dependencies.include?(mod) end
__add_dependent_module(mod)
click to toggle source
# File lib/modulation/module_mixin.rb, line 127 def __add_dependent_module(mod) __dependent_modules << mod unless __dependent_modules.include?(mod) end
__before_reload()
click to toggle source
# File lib/modulation/module_mixin.rb, line 10 def __before_reload @__module_info[:exported_symbols] = [] @__export_directives = nil __reset_dependencies end
__dependencies()
click to toggle source
# File lib/modulation/module_mixin.rb, line 106 def __dependencies @__dependencies ||= [] end
__dependent_modules()
click to toggle source
# File lib/modulation/module_mixin.rb, line 123 def __dependent_modules @__dependent_modules ||= [] end
__export_directives()
click to toggle source
# File lib/modulation/module_mixin.rb, line 16 def __export_directives @__export_directives || [] end
__exported_symbols()
click to toggle source
# File lib/modulation/module_mixin.rb, line 20 def __exported_symbols __module_info[:exported_symbols] end
__expose!()
click to toggle source
Exposes all private methods and private constants as public @return [Module] self
# File lib/modulation/module_mixin.rb, line 92 def __expose! singleton = singleton_class singleton.private_instance_methods.each do |sym| singleton.send(:public, sym) end __module_info[:private_constants].each do |sym| const_set(sym, singleton.const_get(sym)) end self end
__reload!()
click to toggle source
Reload module @return [Module] module
# File lib/modulation/module_mixin.rb, line 80 def __reload! Modulation.reload(self) end
__reset_dependencies()
click to toggle source
# File lib/modulation/module_mixin.rb, line 131 def __reset_dependencies return unless @__dependencies @__dependencies.each do |mod| next unless mod.respond_to?(:__dependent_modules) mod.__dependent_modules.delete(self) end @__dependencies.clear end
__traverse_dependencies(&block)
click to toggle source
# File lib/modulation/module_mixin.rb, line 114 def __traverse_dependencies(&block) __dependencies.each do |mod| block.(mod) if mod.respond_to?(:__traverse_dependencies) mod.__traverse_dependencies(&block) end end end
export(*symbols)
click to toggle source
Adds given symbols to the exported_symbols array @param symbols [Array] array of symbols @return [void]
# File lib/modulation/module_mixin.rb, line 27 def export(*symbols) if @__export_default_info raise 'Cannot mix calls to export and export_default in same module' end @__export_directives ||= [] @__export_directives << { method: :export, args: symbols, export_caller: caller } end
export_default(value)
click to toggle source
Sets a module's value, so when imported it will represent the given value, instead of a module facade @param value [Symbol, any] symbol or value @return [void]
# File lib/modulation/module_mixin.rb, line 59 def export_default(value) unless __export_directives.empty? raise 'Cannot mix calls to export and export_default in the same module' end @__export_default_info = { value: value, caller: caller } end
export_from_receiver(name)
click to toggle source
# File lib/modulation/module_mixin.rb, line 44 def export_from_receiver(name) raise EXPORT_DEFAULT_ERROR_MSG if @__export_default_info @__export_directives ||= [] @__export_directives << { method: :export_from_receiver, args: name, export_caller: caller } end
inspect()
click to toggle source
Returns a text representation of the module for inspection @return [String] module string representation
# File lib/modulation/module_mixin.rb, line 69 def inspect module_name = name || 'Module' if __module_info[:location] "#{module_name}:#{__module_info[:location]}" else module_name end end