Created
August 18, 2014 08:43
-
-
Save mikekreeki/b4f83380ea67b174e40a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module ActiveInteraction | |
class ObjectFilter < Filter | |
register :object | |
def cast(value) | |
@klass ||= klass | |
if matches?(value) | |
value | |
else | |
raise InvalidClassError, value.class.name | |
end | |
end | |
private | |
def klass | |
options[:class] | |
end | |
def matches?(value) | |
return true unless @klass | |
@klass === value || value.is_a?(@klass) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment