class Right::FilterParameterDefinition
Filtering parameter definition
Attributes
as[R]
If the property name doesn't match the name in the query string, use the :as option @return [String]
name[R]
@return [String]
on[R]
Association on which this parameter is defined. @return [String, nil]
predicates[R]
White-listed predicates @return [<String>]
validations[R]
Proc with defined validations @return [Proc] @api private
Public Class Methods
new(name, options = {})
click to toggle source
@param [String] name of the field @param [Hash] options @option options [Symbol, {Symbol => String}, {Symbol => <String>}] :on (nil) filter on given relation @option options [<String>] :predicates (ALL_PREDICATES) white-listed predicates @option options [Proc] :coerce coercion for the value @option options [Hash{Symbol => any}] :validates for the value
@example validates: presence: true, length: { is: 6 }
# File lib/right/filter_parameter_definition.rb, line 30 def initialize(name, options = {}) options.assert_valid_keys(:as, :on, :predicates, :coerce, :validates) @as = options.fetch(:as, name).to_s @name = name.to_s @on = options[:on] @predicates = Array(options.fetch(:predicates, FilterPredicates.all)).map(&:to_s) @coerce = options.fetch(:coerce, ->(v) { v }) @validations = options.fetch(:validates, {}) end
Public Instance Methods
==(other)
click to toggle source
# File lib/right/filter_parameter_definition.rb, line 47 def ==(other) other.is_a?(self.class) && other.name == name && other.as == as && other.on == on && other.predicates == predicates end
coerce(value)
click to toggle source
@param [any] value @return [any] coerced value according the definition
# File lib/right/filter_parameter_definition.rb, line 58 def coerce(value) @coerce.call(value) end
defined?()
click to toggle source
# File lib/right/filter_parameter_definition.rb, line 66 def defined? true end
eql?(other)
click to toggle source
# File lib/right/filter_parameter_definition.rb, line 43 def eql?(other) other.is_a?(self.class) && other.name == name end
undefined?()
click to toggle source
# File lib/right/filter_parameter_definition.rb, line 70 def undefined? !self.defined? end
validator()
click to toggle source
# File lib/right/filter_parameter_definition.rb, line 62 def validator FilterValueValidator.build(self) end