class ActiveInteraction::ArrayFilter
@private
Constants
- FILTER_NAME_OR_OPTION
The array starts with the class override key and then contains any additional options which halt explicit setting of the class.
Private Instance Methods
add_option_in_place_of_name(klass, options)
click to toggle source
# File lib/active_interaction/filters/array_filter.rb, line 75 def add_option_in_place_of_name(klass, options) if (keys = FILTER_NAME_OR_OPTION[klass.to_s]) && (keys & options.keys).empty? options.merge( "#{keys.first}": name.to_s.singularize.camelize.to_sym ) else options end end
adjust_output(value, context)
click to toggle source
# File lib/active_interaction/filters/array_filter.rb, line 58 def adjust_output(value, context) return value if filters.empty? filter = filters.values.first value.map { |e| filter.clean(e, context) } end
convert(value)
click to toggle source
Calls superclass method
ActiveInteraction::Filter#convert
# File lib/active_interaction/filters/array_filter.rb, line 65 def convert(value) if value.respond_to?(:to_ary) value.to_ary else super end rescue NoMethodError # BasicObject super end
klasses()
click to toggle source
# File lib/active_interaction/filters/array_filter.rb, line 41 def klasses %w[ ActiveRecord::Relation ActiveRecord::Associations::CollectionProxy ].each_with_object([Array]) do |name, result| next unless (klass = name.safe_constantize) result.push(klass) end end
matches?(value)
click to toggle source
# File lib/active_interaction/filters/array_filter.rb, line 52 def matches?(value) klasses.any? { |klass| value.is_a?(klass) } rescue NoMethodError # BasicObject false end
method_missing(*, &block)
click to toggle source
rubocop:disable Style/MissingRespondToMissing
Calls superclass method
ActiveInteraction::Missable#method_missing
# File lib/active_interaction/filters/array_filter.rb, line 86 def method_missing(*, &block) super do |klass, names, options| options = add_option_in_place_of_name(klass, options) filter = klass.new(names.first || '', options, &block) filters[filters.size.to_s.to_sym] = filter validate!(names) end end
validate!(names)
click to toggle source
@param filter [Filter] @param names [Array<Symbol>]
@raise [InvalidFilterError]
# File lib/active_interaction/filters/array_filter.rb, line 103 def validate!(names) raise InvalidFilterError, 'multiple filters in array block' if filters.size > 1 raise InvalidFilterError, 'attribute names in array block' unless names.empty? nil end