Class: K4compiler::Config
- Inherits:
-
Object
- Object
- K4compiler::Config
show all
- Defined in:
- lib/k4compiler/config.rb
Constant Summary
collapse
- THIRD_PARTY_DIR =
File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'third_party'))
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13
14
15
|
# File 'lib/k4compiler/config.rb', line 13
def initialize
@root_ = build_struct_recursive(default_options)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/k4compiler/config.rb', line 51
def method_missing(method, *args)
if @root_.respond_to?(method)
@root_.send(method, *args)
else
raise ::NoMethodError.new("undefined local variable or method '#{method}'")
end
end
|
Instance Method Details
#build_struct_recursive(hash = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/k4compiler/config.rb', line 23
def build_struct_recursive(hash={})
struct_hash = {}
hash.each do |key, val|
if val.is_a?(::Hash)
val = build_struct_recursive(val)
end
struct_hash[key] = val
end
return struct(struct_hash)
end
|
#default_options ⇒ Hash
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/k4compiler/config.rb', line 35
def default_options
options = {}
ignore_files = ['.', '..', 'base.rb']
compiler_path = File.join(File.dirname(__FILE__), 'compiler')
Dir.foreach(compiler_path) do |entry|
unless ignore_files.include?(entry)
basename = File.basename(entry).gsub(/\.rb$/, '')
class_name = basename.camelize
eval_method = "K4compiler::#{class_name}.options"
options[basename] = eval(eval_method)
end
end
options = options.with_indifferent_access
return options
end
|
#struct(*args) ⇒ Object
17
18
19
20
|
# File 'lib/k4compiler/config.rb', line 17
def struct(*args)
structure = OpenStruct.new(*args)
return structure
end
|