Class: FastAPI::Comparison
- Inherits:
-
Object
- Object
- FastAPI::Comparison
- Defined in:
- lib/fastapi/comparison.rb
Constant Summary collapse
- @@scalar_input =
{ is: '__FIELD__ = __VALUE__', not: '__FIELD__ <> __VALUE__', gt: '__FIELD__ > __VALUE__', gte: '__FIELD__ >= __VALUE__', lt: '__FIELD__ < __VALUE__', lte: '__FIELD__ <= __VALUE__', like: '__FIELD__ LIKE \'%\' || __VALUE__ || \'%\'', ilike: '__FIELD__ ILIKE \'%\' || __VALUE__ || \'%\'', not_like: 'NOT (__FIELD__ LIKE \'%\' || __VALUE__ || \'%\')', not_ilike: 'NOT (__FIELD__ ILIKE \'%\' || __VALUE__ || \'%\')', null: '__FIELD__ IS NULL', not_null: '__FIELD__ IS NOT NULL' }.with_indifferent_access
- @@multi_input =
{ in: '__FIELD__ IN (__VALUES__)', not_in: '__FIELD__ NOT IN (__VALUES__)', subset: '__FIELD__ <@ ARRAY[__VALUES__]::__TYPE__[]', not_subset: 'NOT __FIELD__ <@ ARRAY[__VALUES__]::__TYPE__[]', contains: '__FIELD__ @> ARRAY[__VALUES__]::__TYPE__[]', not_contains: 'NOT __FIELD__ @> ARRAY[__VALUES__]::__TYPE__[]', intersects: '__FIELD__ && ARRAY[__VALUES__]::__TYPE__[]', not_intersects: 'NOT __FIELD__ && ARRAY[__VALUES__]::__TYPE__[]' }.with_indifferent_access
- @@booleans =
{ t: true, true: true, f: false, false: false }.with_indifferent_access
- @@types =
Hash.new('text').merge({ boolean: 'boolean', integer: 'integer', float: 'float', string: 'varchar' }).with_indifferent_access
Instance Attribute Summary collapse
-
#sql ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute sql.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(comparator, value, field, type) ⇒ Comparison
constructor
A new instance of Comparison.
Constructor Details
#initialize(comparator, value, field, type) ⇒ Comparison
Returns a new instance of Comparison.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fastapi/comparison.rb', line 55 def initialize(comparator, value, field, type) key = prepare_comparator(comparator, value) val = prepare_value(value, type) if clause = @@scalar_input[key] @sql = scalar_sql(clause, field, val) elsif clause = @@multi_input[key] @sql = multi_sql(clause, val, field, type) else raise ArgumentError.new("Invalid comparator: #{key}") end end |
Instance Attribute Details
#sql ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute sql.
4 5 6 |
# File 'lib/fastapi/comparison.rb', line 4 def sql @sql end |
Class Method Details
.invalid_comparator?(comparator) ⇒ Boolean
51 52 53 |
# File 'lib/fastapi/comparison.rb', line 51 def self.invalid_comparator?(comparator) !valid_comparator?(comparator) end |
.valid_comparator?(comparator) ⇒ Boolean
47 48 49 |
# File 'lib/fastapi/comparison.rb', line 47 def self.valid_comparator?(comparator) @@scalar_input.key?(comparator) || @@multi_input.key?(comparator) end |