Class: Right::FilterParameterDefinition
- Inherits:
-
Object
- Object
- Right::FilterParameterDefinition
- Defined in:
- lib/right/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.
30 31 32 33 34 35 36 37 38 |
# File 'lib/right/filter_parameter_definition.rb', line 30 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
8 9 10 |
# File 'lib/right/filter_parameter_definition.rb', line 8 def as @as end |
#name ⇒ String (readonly)
11 12 13 |
# File 'lib/right/filter_parameter_definition.rb', line 11 def name @name end |
#on ⇒ String? (readonly)
Association on which this parameter is defined.
15 16 17 |
# File 'lib/right/filter_parameter_definition.rb', line 15 def on @on end |
#predicates ⇒ <String> (readonly)
White-listed predicates
19 20 21 |
# File 'lib/right/filter_parameter_definition.rb', line 19 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
77 78 79 |
# File 'lib/right/filter_parameter_definition.rb', line 77 def validations @validations end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 50 51 52 53 |
# 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) ⇒ any
Returns coerced value according the definition.
58 59 60 |
# File 'lib/right/filter_parameter_definition.rb', line 58 def coerce(value) @coerce.call(value) end |
#defined? ⇒ Boolean
66 67 68 |
# File 'lib/right/filter_parameter_definition.rb', line 66 def defined? true end |
#eql?(other) ⇒ Boolean
43 44 45 |
# File 'lib/right/filter_parameter_definition.rb', line 43 def eql?(other) other.is_a?(self.class) && other.name == name end |
#undefined? ⇒ Boolean
70 71 72 |
# File 'lib/right/filter_parameter_definition.rb', line 70 def undefined? !self.defined? end |
#validator ⇒ Object
62 63 64 |
# File 'lib/right/filter_parameter_definition.rb', line 62 def validator FilterValueValidator.build(self) end |