Module: ConfigDSL::DSL
- Extended by:
- ActiveSupport::Concern
- Included in:
- Processor::Sandbox
- Defined in:
- lib/configdsl.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/configdsl.rb', line 156
def method_missing(meth, *args, &block)
if respond_to?(meth)
super
else
varibales_hook(meth, *args, &block)
end
end
|
Class Method Details
.debug!(value = true) ⇒ Object
104
105
106
|
# File 'lib/configdsl.rb', line 104
def self.debug!(value = true)
@debug = value
end
|
.debug? ⇒ Boolean
100
101
102
|
# File 'lib/configdsl.rb', line 100
def self.debug?
@debug ||= false
end
|
Instance Method Details
#assign!(sym, value = nil, &block) ⇒ Object
120
121
122
123
|
# File 'lib/configdsl.rb', line 120
def assign!(sym, value = nil, &block)
return sym.each { |key, val| assign!(key, val) } if sym.kind_of? Hash
varibales_hook(sym, value, &block)
end
|
#context ⇒ Object
108
109
110
|
# File 'lib/configdsl.rb', line 108
def context
@@context ||= []
end
|
#debug(text) ⇒ Object
112
113
114
|
# File 'lib/configdsl.rb', line 112
def debug(text)
puts text if DSL.debug?
end
|
#evaluate_within_layer(new_layer, block, args = []) ⇒ Object
146
147
148
149
150
151
152
153
154
|
# File 'lib/configdsl.rb', line 146
def evaluate_within_layer(new_layer, block, args = [])
Memory.add_layer(new_layer, context)
begin
context.push new_layer
block.call(*args)
ensure
context.pop
end
end
|
#lazy!(*args, &block) ⇒ Object
116
117
118
|
# File 'lib/configdsl.rb', line 116
def lazy!(*args, &block)
LazyValue.new(block, args)
end
|
#varibales_hook(meth, *args, &block) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/configdsl.rb', line 125
def varibales_hook(meth, *args, &block)
debug "Hooked #{meth}"
debug "Context is #{context}"
if block_given?
debug "Adding list #{meth}"
evaluate_within_layer(meth, block, args)
else
if args.empty?
debug "Reading variable #{meth}"
Memory.fetch!(meth, context)
else
debug "Adding variable #{meth}"
value = args.size == 1 ? args.first : args.dup
Memory.store(meth, value, context)
end
end
end
|