Module: Baltix::Loader::Certain
- Includes:
- Baltix::Log, Rake::DSL
- Defined in:
- lib/baltix/loader.rb
Constant Summary
Constants included
from Baltix::Log
Baltix::Log::DEFAULT_IO_NAMES
Instance Attribute Summary collapse
Instance Method Summary
collapse
default_prefix, io_name_parse, ios, level, #level_match, #log, prefix, prefix_for, setup, setup_kind
Instance Attribute Details
#object_hash ⇒ Object
Returns the value of attribute object_hash.
13
14
15
|
# File 'lib/baltix/loader.rb', line 13
def object_hash
@object_hash
end
|
#object_ids ⇒ Object
Returns the value of attribute object_ids.
13
14
15
|
# File 'lib/baltix/loader.rb', line 13
def object_ids
@object_ids
end
|
Instance Method Details
#load_file(file, type_hash) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/baltix/loader.rb', line 46
def load_file file, type_hash
store_object_hash(type_hash)
value = nil
begin
push
Dir.chdir(File.dirname(file)) do
_file = File.basename(file).untaint
code = File.read(file, mode: 'r:UTF-8:-')
code.untaint
value =
begin
instance_eval(code, _file)
rescue Exception
load(File.basename(file), true)
end
end
rescue Exception => e
raise e
ensure
debug("value: #{value.inspect}")
pop
store_object_hash(type_hash)
end
self
rescue Exception => e
debug("[#{e.class}]: #{e.message}\n\t#{e.backtrace.join("\n\t")}")
self
end
|
#pop ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/baltix/loader.rb', line 91
def pop
debug("Subtract paths: " + ($: - @paths).join("\n\t"))
$:.replace(@paths | $:)
debug("Replaced paths with: " + $:.join("\n\t"))
end
|
#push ⇒ Object
86
87
88
89
|
# File 'lib/baltix/loader.rb', line 86
def push
@paths = $:.dup
debug("Stored paths are: " + @paths.join("\n\t"))
end
|
#require(*args) ⇒ Object
17
18
19
20
21
|
# File 'lib/baltix/loader.rb', line 17
def require *args
require_orig(*args)
rescue LoadError
true
end
|
#require_orig ⇒ Object
15
|
# File 'lib/baltix/loader.rb', line 15
alias_method :require_orig, :require
|
#store_object_hash(type_hash) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/baltix/loader.rb', line 23
def store_object_hash type_hash
object_hash =
type_hash.map do |(klass, types)|
objects = types.split(',').map do |type|
begin
ObjectSpace.each_object(type.constantize).map { |h| h }
rescue NameError
[]
end
end.flatten
[klass, objects]
end.to_h
if @object_hash
@object_ids = object_hash.map do |(k, oh)|
[k, oh.map {|h| h.__id__ } - @object_hash[k].map {|h| h.__id__ }]
end.to_h
end
@object_hash = object_hash
end
|