Class: Might::FilterParameterDefinition
- Inherits:
-
Object
- Object
- Might::FilterParameterDefinition
- Defined in:
- lib/might/filter_parameter_definition.rb
Overview
Filtering parameter definition
Direct Known Subclasses
Instance Attribute Summary collapse
-
#as ⇒ String
readonly
If the property name doesn’t match the name in the query string, use the :as option.
- #name ⇒ String readonly
-
#on ⇒ String?
readonly
Association on which this parameter is defined.
-
#predicates ⇒ <String>
readonly
White-listed predicates.
-
#validations ⇒ Proc
readonly
private
Proc with defined validations.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#coerce(value) ⇒ any
Coerced value according the definition.
- #defined? ⇒ Boolean
- #eql?(other) ⇒ Boolean
-
#initialize(name, options = {}) ⇒ FilterParameterDefinition
constructor
A new instance of FilterParameterDefinition.
- #undefined? ⇒ Boolean
- #validator ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ FilterParameterDefinition
Returns a new instance of FilterParameterDefinition.
33 34 35 36 37 38 39 40 41 |
# File 'lib/might/filter_parameter_definition.rb', line 33 def initialize(name, = {}) .assert_valid_keys(:as, :on, :predicates, :coerce, :validates) @as = .fetch(:as, name).to_s @name = name.to_s @on = [:on] @predicates = Array(.fetch(:predicates, FilterPredicates.all)).map(&:to_s) @coerce = .fetch(:coerce, ->(v) { v }) @validations = .fetch(:validates, {}) end |
Instance Attribute Details
#as ⇒ String (readonly)
If the property name doesn’t match the name in the query string, use the :as option
11 12 13 |
# File 'lib/might/filter_parameter_definition.rb', line 11 def as @as end |
#name ⇒ String (readonly)
14 15 16 |
# File 'lib/might/filter_parameter_definition.rb', line 14 def name @name end |
#on ⇒ String? (readonly)
Association on which this parameter is defined.
18 19 20 |
# File 'lib/might/filter_parameter_definition.rb', line 18 def on @on end |
#predicates ⇒ <String> (readonly)
White-listed predicates
22 23 24 |
# File 'lib/might/filter_parameter_definition.rb', line 22 def predicates @predicates end |
#validations ⇒ Proc (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Proc with defined validations
80 81 82 |
# File 'lib/might/filter_parameter_definition.rb', line 80 def validations @validations end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/might/filter_parameter_definition.rb', line 50 def ==(other) other.is_a?(self.class) && other.name == name && other.as == as && other.on == on && other.predicates == predicates end |
#coerce(value) ⇒ any
Returns coerced value according the definition.
61 62 63 |
# File 'lib/might/filter_parameter_definition.rb', line 61 def coerce(value) @coerce.call(value) end |
#defined? ⇒ Boolean
69 70 71 |
# File 'lib/might/filter_parameter_definition.rb', line 69 def defined? true end |
#eql?(other) ⇒ Boolean
46 47 48 |
# File 'lib/might/filter_parameter_definition.rb', line 46 def eql?(other) other.is_a?(self.class) && other.name == name end |
#undefined? ⇒ Boolean
73 74 75 |
# File 'lib/might/filter_parameter_definition.rb', line 73 def undefined? !self.defined? end |
#validator ⇒ Object
65 66 67 |
# File 'lib/might/filter_parameter_definition.rb', line 65 def validator FilterValueValidator.build(self) end |