Class: Warped::Filter::Base
- Inherits:
-
Object
- Object
- Warped::Filter::Base
- Defined in:
- lib/warped/api/filter/base.rb,
lib/warped/api/filter/base/value.rb
Defined Under Namespace
Classes: Value
Constant Summary collapse
- RELATIONS =
%w[eq neq gt gte lt lte between in not_in starts_with ends_with contains is_null is_not_null].freeze
Instance Attribute Summary collapse
-
#alias_name ⇒ Object
readonly
Returns the value of attribute alias_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
Class Method Summary collapse
-
.kind ⇒ Symbol?
The filter kind.
Instance Method Summary collapse
-
#cast(value) ⇒ Object
The casted value.
-
#html_type ⇒ String
The HTML input type.
-
#initialize(name, strict:, alias_name: nil, **options) ⇒ Base
constructor
A new instance of Base.
-
#kind ⇒ Symbol?
The filter kind.
-
#parameter_name ⇒ String
The name to use in the URL params.
-
#relation(relation) ⇒ String
The validated filter relation.
-
#relations ⇒ Array<String>
The valid filter relations.
Constructor Details
#initialize(name, strict:, alias_name: nil, **options) ⇒ Base
Returns a new instance of Base.
26 27 28 29 30 31 32 33 |
# File 'lib/warped/api/filter/base.rb', line 26 def initialize(name, strict:, alias_name: nil, **) raise ArgumentError, "name cannot be nil" if name.nil? @name = name.to_s @strict = strict @alias_name = alias_name&.to_s @options = end |
Instance Attribute Details
#alias_name ⇒ Object (readonly)
Returns the value of attribute alias_name.
12 13 14 |
# File 'lib/warped/api/filter/base.rb', line 12 def alias_name @alias_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/warped/api/filter/base.rb', line 12 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/warped/api/filter/base.rb', line 12 def @options end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
12 13 14 |
# File 'lib/warped/api/filter/base.rb', line 12 def strict @strict end |
Class Method Details
.kind ⇒ Symbol?
Returns The filter kind.
17 18 19 20 21 |
# File 'lib/warped/api/filter/base.rb', line 17 def self.kind filter_type = name.demodulize.underscore.to_sym filter_type == :filter ? nil : filter_type end |
Instance Method Details
#cast(value) ⇒ Object
Returns The casted value.
48 49 50 51 52 |
# File 'lib/warped/api/filter/base.rb', line 48 def cast(value) return if value.nil? value end |
#html_type ⇒ String
Returns The HTML input type.
73 74 75 |
# File 'lib/warped/api/filter/base.rb', line 73 def html_type raise NotImplementedError, "#{self.class.name}#html_type not implemented" end |
#kind ⇒ Symbol?
Returns The filter kind.
36 37 38 |
# File 'lib/warped/api/filter/base.rb', line 36 def kind self.class.kind end |
#parameter_name ⇒ String
Returns The name to use in the URL params.
68 69 70 |
# File 'lib/warped/api/filter/base.rb', line 68 def parameter_name alias_name.presence || name end |
#relation(relation) ⇒ String
Returns The validated filter relation.
57 58 59 60 61 62 63 64 65 |
# File 'lib/warped/api/filter/base.rb', line 57 def relation(relation) if valid_relation?(relation) relation else raise RelationError, "Invalid relation: #{relation}" unless strict "eq" end end |
#relations ⇒ Array<String>
Returns The valid filter relations.
41 42 43 |
# File 'lib/warped/api/filter/base.rb', line 41 def relations self.class::RELATIONS end |