- A Filter is a Ruby module with a :process method that accepts text (like MarkDown) and filters it in some way. This is for a CMS. Filters do not get stored in the database.
- A FilterGroup is (as it likely sounds) a list of Filters to apply to some piece of content. FilterGroups do get stored in the database.
- Implemented FilterArray as suggested by http://groups.google.com/group/mongomapper/browse_thread/thread/4132688f57f41d17
Created
August 4, 2010 02:06
-
-
Save ravinggenius/507531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Filter | |
def initialize(name) | |
@name = name | |
end | |
def name | |
@name.gsub /\.rb/, '' | |
end | |
# this loads the filter module | |
def filter | |
@filter ||= name.camelize.constantize | |
end | |
def self.all | |
# ... | |
end | |
def self.process_all(input, filter_group) | |
filter_group.filters.each do |f| | |
input = f.filter.process input | |
end | |
input | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilterArray < Array | |
def self.to_mongo(values) | |
values ||= [] | |
values.map { |v| v.respond_to?(:name) ? v.name : v } | |
end | |
def self.from_mongo(values) | |
values ||= [] | |
values.map { |v| v.respond_to?(:name) ? v : Filter["#{v}.rb"] } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FilterGroup | |
include MongoMapper::Document | |
key :name, String, :required => true | |
key :filters, FilterArray, :required => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment