Module: Interop
- Defined in:
- lib/interop.rb
Constant Summary collapse
Class Method Summary collapse
- .cleanly_load(targets) ⇒ Object
- .import(id) ⇒ Object
- .wrap_constants(new, result = {}, visited = Set.new) ⇒ Object
Class Method Details
.cleanly_load(targets) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/interop.rb', line 23 def self.cleanly_load(targets) DEBUG.call "Package definitions #{targets}" result = wrap_constants(targets) result.each_pair do |key, value| Object.send(:remove_const, key.to_sym) unless key.include?('::') end result end |
.import(id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/interop.rb', line 11 def self.import(id) if @cache.include?(id) DEBUG.call "Cache hit #{id}" return @cache[id] end DEBUG.call "Load #{id}" snapshot = Module.constants require id cleanly_load(Module.constants - snapshot) end |
.wrap_constants(new, result = {}, visited = Set.new) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/interop.rb', line 33 def self.wrap_constants(new, result={}, visited=Set.new) if new.length == 0 return result end str = new.pop().to_s const = eval str if const.nil? return wrap_constants(new, result) end if const.respond_to? :constants children = const .constants .reject {|element| visited.include?(element)} .map {|child| visited.add(child) "#{str}::#{child.to_s}" } new += children end result[str] = const.class == Module ? Class.new.extend(const) : const return wrap_constants(new, result, visited) end |