Module: ActiveInteraction::Extras::FilterExtensions::ObjectClasses
- Defined in:
- lib/active_interaction/extras/filter_extensions/object_classes.rb
Overview
Add support for polymorphic objects
object :account, class: [Account, AnyoneAccount]
Instance Method Summary collapse
- #class_list ⇒ Object
- #class_names ⇒ Object
- #klass ⇒ Object
- #matches?(value) ⇒ Boolean
- #polymorphic? ⇒ Boolean
Instance Method Details
#class_list ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/active_interaction/extras/filter_extensions/object_classes.rb', line 7 def class_list class_names.map do |klass_name| case klass_name when Class klass_name else begin Object.const_get(klass_name.to_s.camelize) rescue NameError raise ActiveInteraction::InvalidNameError, "class #{klass_name.inspect} does not exist" end end end end |
#class_names ⇒ Object
40 41 42 |
# File 'lib/active_interaction/extras/filter_extensions/object_classes.rb', line 40 def class_names .fetch(:class, name) end |
#klass ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/active_interaction/extras/filter_extensions/object_classes.rb', line 22 def klass if polymorphic? class_list.first else super end end |
#matches?(value) ⇒ Boolean
30 31 32 33 34 35 36 37 38 |
# File 'lib/active_interaction/extras/filter_extensions/object_classes.rb', line 30 def matches?(value) if polymorphic? return false if value == nil class_list.any? { |klass| value.class <= klass } else super end end |
#polymorphic? ⇒ Boolean
44 45 46 |
# File 'lib/active_interaction/extras/filter_extensions/object_classes.rb', line 44 def polymorphic? class_names.is_a? Array end |