Skip to content

Instantly share code, notes, and snippets.

@mikekreeki
Created August 18, 2014 08:43
Show Gist options
  • Save mikekreeki/b4f83380ea67b174e40a to your computer and use it in GitHub Desktop.
Save mikekreeki/b4f83380ea67b174e40a to your computer and use it in GitHub Desktop.
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