359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
# File 'lib/nested.rb', line 359
def self.generate_function_name(resource, method, action)
arr = []
arr << "update" if method == :put
arr << "create" if method == :post
arr << "destroy" if method == :delete
parents = resource.parents
parents.each_with_index do |p, idx|
if p.collection? && method != :post && ((parents[idx + 1] && parents[idx + 1].singleton?) || parents.last == p)
arr << p.name.to_s.send(:pluralize)
else
arr << p.name.to_s.send(:singularize)
end
end
if resource.member?
if resource.parent
arr = arr.slice(0...-1)
arr << resource.parent.name.to_s.send(:singularize)
else
arr << resource.name.to_s.send(:singularize)
end
elsif resource.singleton?
arr << resource.name.to_s.send(:singularize)
elsif resource.collection?
if method == :post
arr << resource.name.to_s.send(:singularize)
else
arr << resource.name.to_s.send(:pluralize)
end
end
arr << action if action
arr.map(&:to_s).join("_").camelcase(:lower)
end
|