52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/deltacloud/helpers/rabbit_helper.rb', line 52
def self.generate_url_helper_for(collection, operation)
operation_name = operation.operation_name.to_s
collection_name = collection.collection_name.to_s
helper_method_name = case operation_name
when 'index' then collection_name
when 'show' then collection_name.singularize
else operation_name + '_' + collection_name.singularize
end
helper_method_name += '_url'
[Proc.new do
define_method helper_method_name do |*args|
if (opts = args.first).kind_of? Hash
path = operation.full_path.convert_query_params(opts)
elsif !args.empty? and (obj_id = args.first)
path = operation.full_path.convert_query_params(:id => obj_id)
elsif operation_name == 'show'
path = collection.operation(:index).full_path
else
path = operation.full_path
end
path.slice!(root_url) if path.start_with?(root_url)
url(path)
end unless respond_to?(helper_method_name)
end, helper_method_name]
end
|