-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmoduledef.rb
More file actions
67 lines (49 loc) · 1.53 KB
/
Copy pathmoduledef.rb
File metadata and controls
67 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
59
60
61
62
63
64
65
66
67
require_relative 'modulecache'
=begin
A ModuleDef represents a logical module on DCL. The constraints on DCL are
defined upon the ModuleDef objects
=end
class ModuleDef
attr_accessor :name, :paths
@name = ''
@paths = []
@loaded = false
def initialize(name, paths)
# Defines the main variables and caches all the names associated with
# the modules
@name = name
@paths = paths
@loaded = false
self.load
end
# Loads modules in this moduledef to use
def load
@paths.each do |mod_name|
globals_of_module(mod_name)
end
@loaded = true
end
def has(cls)
# We need to lazy load the modules, otherwise, all modules will be
# loaded and his code wouldnt be instrumented
if not @loaded
load
end
# Given a class, discover if self contains it
valids = @paths.find_all { |x| ModuleCache.get_mod(x, cls.class.name) != []}
valids != []
end
def to_s
"#<ModuleDef: name=>#{@name}, paths=>#{@paths}>"
end
end
if __FILE__ == $0
$:.unshift File.join(File.dirname(__FILE__),'..')
$:.unshift File.join(File.dirname(__FILE__),'.')
#require_relative 'system/model'
#require_relative 'system/view'
view = ModuleDef.new(:A, ['system/view'])
mod = ModuleDef.new(:B, ['system/model'])
puts view.has(ModuleIncluded)
puts mod.has(ModuleIncluded)
end