Permalink
Browse files

configurable url path

  • Loading branch information...
1 parent acb7818 commit c95969698657217f0f46743322c1fdd791115c41 S. Brent Faulkner committed Feb 4, 2009
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/sequel_container.rb
View
@@ -12,6 +12,7 @@ def contains(object, options = {})
return object.each { |o| contains(o, options) } if object.is_a? Array
container = table_name
+ url_template = options[:url] || '/:container/:id/:filename'
class_eval <<-CONTAINED_PATH, __FILE__, __LINE__ + 1
def #{object}_path
@@ -24,7 +25,19 @@ def #{object}_path
def #{object}_url
return unless #{object}?
@#{object}_path ||= write_#{object}
- @#{object}_url ||= "/#{container}/\#{id}/\#{#{object}_filename}"
+ @#{object}_url ||= "#{url_template}".gsub(/:(\\w+)/) do |m|
+ sym = $1.to_sym
+ case sym
+ when :container
+ "#{container}"
+ when :filename
+ send("#{object}_filename")
+ when :extension
+ send("#{object}_extension")
+ else
+ send(sym)
+ end
+ end
end
CONTAINED_URL

0 comments on commit c959696

Please sign in to comment.