414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
# File 'lib/nested.rb', line 414
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
|