271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/saki.rb', line 271
def self.method_missing(methId, *args)
parse_opts = lambda {|link , opts, context|
opts ||= {}
if opts[:parent]
"/#{opts[:parent].to_s.pluralize}/#{(context.instance_variable_get('@' + opts[:parent].to_s)).id}" + link
else
link
end
}
str = methId.id2name
if str.match /new_(.*)_path/
lambda { |context|
parse_opts.call "/#{$1.pluralize}/new", args.first, context
}
elsif str.match /edit_(.*)_path/
lambda { |context|
model = context.instance_variable_get "@#{$1}"
parse_opts.call "/#{model.class.to_s.tableize}/#{model.id}/edit", args.first, context
}
elsif str.match /(.*)_path/
pluralized = $1.pluralize
if pluralized == $1
lambda { |context| parse_opts.call "/#{$1}", args.first, context }
else
lambda { |context|
model = context.instance_variable_get "@#{$1}"
parse_opts.call "/#{model.class.to_s.tableize}/#{model.id}", args.first, context
}
end
else
super(methId, [])
end
end
|