Class: Base
- Inherits:
-
Object
show all
- Defined in:
- lib/libisi/base.rb
Direct Known Subclasses
Attribute, Bridge, Cache, Chart, Color, Concept, Doc, Environment, Instance, Log, Property, Relation, Request, Uri, Value
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.add_output(new_child) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/libisi/base.rb', line 51
def self.add_output(new_child)
curr = global_variable
$log.debug("Current #{self.name} is #{curr.class.name}")
case curr
when NilClass
$log.debug("Setting new child as only instance.")
curr = new_child
when Tee
$log.debug("Setting new child as tee to #{curr.children.length} other instance.")
curr.add_child(new_child)
else
$log.debug("Setting new child with new tee to another instance.")
curr = Tee.new([curr, new_child])
end
self.global_variable = curr
curr
end
|
.change(type, options = {}) ⇒ Object
85
86
87
88
|
# File 'lib/libisi/base.rb', line 85
def self.change(type, options = {})
$log.debug("Change #{self.class.name} to type #{type} with options #{options.inspect}")
self.global_variable = create(type, options)
end
|
.create(type_name, options = {}) ⇒ Object
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/libisi/base.rb', line 98
def self.create(type_name, options = {})
klass = load(type_name)
if klass.respond_to?(:instanciate)
ret = klass.instanciate(options)
raise "#{klass.name} created null object!" if ret.nil?
ret
else
klass.new(options)
end
end
|
.create_output(type, ending, file) ⇒ Object
69
70
71
72
|
# File 'lib/libisi/base.rb', line 69
def self.create_output(type, ending, file)
$log.debug("Create new output of type #{type} to file #{file}")
create(type,:writer => file.open("w"))
end
|
.global_variable ⇒ Object
78
79
80
|
# File 'lib/libisi/base.rb', line 78
def self.global_variable
eval("$#{self.name.downcase}")
end
|
.global_variable=(val) ⇒ Object
81
82
83
|
# File 'lib/libisi/base.rb', line 81
def self.global_variable=(val)
eval("$#{self.name.downcase} = val")
end
|
.init(options = {}) ⇒ Object
74
75
76
|
# File 'lib/libisi/base.rb', line 74
def self.init(options = {})
$log.debug("Initialize #{self.class.name}")
end
|
.load(type_name, options = {}) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/libisi/base.rb', line 90
def self.load(type_name, options = {})
type_name = type_name.to_s
raise "Hacking attack!!" unless type_name.class == String
raise "Unexpected #{self.name} name #{type_name}." unless type_name =~ /^[a-zA-Z][a-zA-Z0-9]*$/
require "libisi/#{self.name.downcase}/#{type_name}.rb"
eval("#{type_name.capitalize}#{self.name}")
end
|
.output(file) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/libisi/base.rb', line 32
def self.output(file)
$log.debug("Looking for outputter in #{self.name} for file #{file}")
return false unless (file.to_s =~ /\.([^\.]+)$/)
ending = $1
t = type_from_ending(ending)
$log.debug("Type for ending #{ending.inspect} is #{t.inspect}")
return false unless t
file = Pathname.new(file)
new_child = create_output(t, ending, file)
return true unless new_child
add_output(new_child)
end
|
.output_endings ⇒ Object
22
23
24
|
# File 'lib/libisi/base.rb', line 22
def self.output_endings
output_types.map {|key, endings| endings}.flatten.sort
end
|
.type_from_ending(ending) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/libisi/base.rb', line 25
def self.type_from_ending(ending)
output_types.each {|t, endings|
return t if endings.include?(ending)
}
nil
end
|
Instance Method Details
#output_types ⇒ Object
21
|
# File 'lib/libisi/base.rb', line 21
def output_types; {}; end
|