Module: Toast::ConfigDSL::Common
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
6
7
8
|
# File 'lib/toast/config_dsl/common.rb', line 6
def method_missing method, *args
raise_config_error "Unknown directive: `#{method}'"
end
|
Instance Method Details
#check_symbol_list(list) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/toast/config_dsl/common.rb', line 10
def check_symbol_list list
unless list.is_a?(Array) and list.all?{|x| x.is_a? Symbol}
raise_config_error "Directive requires a list of symbols.\n"+
" #{list.map{|x| x.inspect}.join(', ')} ?"
end
end
|
#initialize(config_data = nil) ⇒ Object
2
3
4
|
# File 'lib/toast/config_dsl/common.rb', line 2
def initialize config_data=nil
@config_data = config_data
end
|
#raise_config_error(message = '') ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/toast/config_dsl/common.rb', line 17
def raise_config_error message=''
match = caller.grep(/#{Toast::ConfigDSL.cfg_name}/).first
file_line = if match.nil?
Toast::ConfigDSL.cfg_name
else
match.split(':in').first
end
message += "\n directive: /#{Toast::ConfigDSL.stack.join('/')}"
message += "\n in file : #{file_line}"
Toast.raise_config_error message
end
|
#stack_push(level, &block) ⇒ Object
… to not forget to pop use:
33
34
35
36
37
|
# File 'lib/toast/config_dsl/common.rb', line 33
def stack_push level, &block
Toast::ConfigDSL.stack << level
yield
Toast::ConfigDSL.stack.pop
end
|