Class: ActiveInteraction::ObjectFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/active_interaction/filters/object_filter.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary

Attributes inherited from Filter

#filters, #name, #options

Instance Method Summary collapse

Methods inherited from Filter

#clean, #database_column_type, #default, #default?, #desc, factory, #initialize

Constructor Details

This class inherits a constructor from ActiveInteraction::Filter

Instance Method Details

#cast(value, context, reconstantize: true, convert: true) ⇒ Object

rubocop:disable Metrics/MethodLength

Since:

  • 1.0.0



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_interaction/filters/object_filter.rb', line 33

def cast(value, context, reconstantize: true, convert: true)
  @klass ||= klass

  if matches?(value)
    value
  elsif reconstantize
    @klass = klass
    public_send(__method__, value, context,
      reconstantize: false,
      convert: convert
    )
  elsif !value.nil? && convert && (converter = options[:converter])
    value = convert(klass, value, converter)
    public_send(__method__, value, context,
      reconstantize: reconstantize,
      convert: false
    )
  else
    super(value, context)
  end
end