453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
# File 'lib/nested.rb', line 453
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
|