Permalink
Browse files

add query method for testing for content presence

  • Loading branch information...
1 parent b9f7e48 commit 48ccd333e4a284d2f35d8cc01775bf7861130367 S. Brent Faulkner committed Jan 20, 2009
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/sequel_container.rb
View
12 lib/sequel_container.rb
@@ -15,22 +15,28 @@ def contains(object, options = {})
class_eval <<-CONTAINED_PATH, __FILE__, __LINE__ + 1
def #{object}_path
- return if #{object}_data.nil? || #{object}_data.empty?
+ return unless #{object}?
@#{object}_path ||= write_#{object}
end
CONTAINED_PATH
class_eval <<-CONTAINED_URL, __FILE__, __LINE__ + 1
def #{object}_url
- return if #{object}_data.nil? || #{object}_data.empty?
+ return unless #{object}?
@#{object}_path ||= write_#{object}
@#{object}_url ||= "/#{container}/\#{id}/\#{#{object}_filename}"
end
CONTAINED_URL
+ class_eval <<-CONTAINED_QUERY, __FILE__, __LINE__ + 1
+ def #{object}?
+ !#{object}_data.nil?
+ end
+ CONTAINED_QUERY
+
class_eval <<-CONTAINED_IMAGE, __FILE__, __LINE__ + 1
def #{object}_image?
- #{object}_type[0,6] == 'image/'
+ #{object}? && #{object}_type[0,6] == 'image/'
end
CONTAINED_IMAGE

0 comments on commit 48ccd33

Please sign in to comment.