Class: ActionController::CodeGeneration::GenerationGenerator
Overview
Constant Summary
collapse
- Attributes =
[:after, :before, :current, :segments]
- FieldsToDuplicate =
CodeGenerator::FieldsToDuplicate + Attributes
CodeGenerator::BeginKeywords, CodeGenerator::Keywords, CodeGenerator::ResumeKeywords
Instance Attribute Summary
#locals, #source
Instance Method Summary
collapse
#dup, #indent, #line, #method_missing, #share_locals_with, #to_s
Constructor Details
Returns a new instance of GenerationGenerator.
171
172
173
174
175
176
|
# File 'lib/action_controller/code_generation.rb', line 171
def initialize(*args)
super(*args)
@after, @before = [], []
@current = nil
@segments = []
end
|
Instance Method Details
#add_segment(*segments) {|d| ... } ⇒ Object
200
201
202
203
204
|
# File 'lib/action_controller/code_generation.rb', line 200
def add_segment(*segments)
d = dup
d.segments.concat segments
yield d
end
|
#check_conditions(conditions) ⇒ Object
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/action_controller/code_generation.rb', line 223
def check_conditions(conditions)
tests = []
generator = nil
conditions.each do |key, condition|
tests << (generator || self).hash_value(key, true) if condition.is_a? Regexp
tests << Routing.test_condition((generator || self).hash_value(key, false), condition)
generator = self.dup unless generator
end
return tests.join(' && ')
end
|
212
213
214
215
216
217
|
# File 'lib/action_controller/code_generation.rb', line 212
def continue
d = dup
d.before << d.current
d.current = d.after.shift
d.go
end
|
#expire_for_keys(*keys) ⇒ Object
194
195
196
197
198
|
# File 'lib/action_controller/code_generation.rb', line 194
def expire_for_keys(*keys)
return if keys.empty?
conds = keys.collect {|key| "expire_on[#{key.to_sym.inspect}]"}
line "not_expired, #{hash_name} = false, options if not_expired && #{conds.join(' && ')}"
end
|
219
220
221
|
# File 'lib/action_controller/code_generation.rb', line 219
def finish
line %("/#{segments.join('/')}")
end
|
206
207
208
209
210
|
# File 'lib/action_controller/code_generation.rb', line 206
def go
if current then current.write_generation(self)
else self.finish
end
end
|
#hash_name ⇒ Object
178
|
# File 'lib/action_controller/code_generation.rb', line 178
def hash_name() 'hash' end
|
#hash_value(key, assign = true, default = nil) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/action_controller/code_generation.rb', line 181
def hash_value(key, assign = true, default = nil)
if locals.include?(local_name(key)) then code = local_name(key)
else
code = "hash[#{key.to_sym.inspect}]"
if assign
code = "(#{local_name(key)} = #{code})"
locals << local_name(key)
end
end
code = "(#{code} || (#{default.inspect}))" if default
return code
end
|
#local_name(key) ⇒ Object
179
|
# File 'lib/action_controller/code_generation.rb', line 179
def local_name(key) "#{key}_value" end
|