Class: Bake::Context
Constant Summary
collapse
- DEFAULT_SEARCH_DIR =
File.join(File.dirname(__FILE__), '..')
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#load_child_plugin, #load_plugin
Constructor Details
#initialize(sys) ⇒ Context
Returns a new instance of Context.
12
13
14
15
16
17
|
# File 'lib/bake/context.rb', line 12
def initialize(sys)
@sys = sys
@current = nil
@commands = {}
@default_toolset = Toolset.new(@sys)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/bake/context.rb', line 73
def method_missing(name, *args, &block)
command = @commands[name]
return call(command, *args, &block) if command
if @current
if @current.respond_to?(name)
return @current.send(name, *args, &block)
end
@current[:addons].each do |addon|
command = addon.commands[name]
return call(command, *args, &block) if command
end
end
raise "unknown command '#{name}'"
end
|
Instance Attribute Details
Returns the value of attribute current.
10
11
12
|
# File 'lib/bake/context.rb', line 10
def current
@current
end
|
Returns the value of attribute default_toolset.
10
11
12
|
# File 'lib/bake/context.rb', line 10
def default_toolset
@default_toolset
end
|
Class Method Details
.const_missing(name) ⇒ Object
88
89
90
91
92
|
# File 'lib/bake/context.rb', line 88
def self.const_missing(name)
context = Thread.current[:bake_context]
return super if !context
context.load_plugin("Bake::Plugins::#{name}")
end
|
Instance Method Details
#context_eval(target, str = nil, file = nil, &block) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/bake/context.rb', line 47
def context_eval(target, str = nil, file = nil, &block)
context = Thread.current[:bake_context]
if !context.nil? && !context.equal?(self)
raise 'multiple overlapping contexts detected'
end
Thread.current[:bake_context] = self
old = @current
begin
@current = target
if str
instance_eval(str, file ? file : '')
else
instance_eval(&block)
end
ensure
@current = old
Thread.current[:bake_context] = nil
end
end
|
#import(*addon_classes) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/bake/context.rb', line 19
def import(*addon_classes)
addon_classes.each do |addon_class|
if addon_class.inherits?(Toolset)
addon = addon_class.new(@sys)
else
addon = addon_class.new
end
addon.commands.each_pair do |name, block|
register(name, &block)
end
end
end
|
#register(name, &block) ⇒ Object
43
44
45
|
# File 'lib/bake/context.rb', line 43
def register(name, &block)
@commands[name] = block
end
|
#search_dirs ⇒ Object
67
68
69
70
71
|
# File 'lib/bake/context.rb', line 67
def search_dirs
search_dirs = [ DEFAULT_SEARCH_DIR ]
return search_dirs if !@current
return search_dirs + @current[:plugin_paths]
end
|
#using(*addon_classes) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/bake/context.rb', line 32
def using(*addon_classes)
addon_classes.each do |addon_class|
if addon_class.inherits?(Toolset)
addon = addon_class.new(@sys)
else
addon = addon_class.new
end
@current.opt(:addons => addon)
end
end
|