Module: ActiveRecord::Refined::AST::JsonComparable
- Included in:
- JsonAggregate, JsonBuild, JsonExcept, JsonKeys, JsonPath, JsonSet
- Defined in:
- lib/active_record/refined/ast.rb
Overview
Reading inside a JSON document. Every adapter can do it and no two spell it alike: PostgreSQL walks an array of steps, SQLite has the operators with a $ path, and MySQL has the functions -- which is what this uses for that family, since MariaDB answers to the same adapter and has no -> at all.
The path is turned into a string either way, so a key with a space or
a quote in it travels as itself rather than having to be refused.
What a dug value may be compared with. dig_text gives text on every
adapter, and what a text value compared with a number means is a
question the three answer three ways: dig_text(:n) == 5 is true on
SQLite, an error on PostgreSQL and true on MySQL, while
dig_text(:flag) == true is true, an error, and false. cast is what
says which type was meant, and then all three agree.
dig, bury and except give JSON, and a JSON comparison belongs to the JSON types -- jsonb and MySQL's -- where numbers compare as numbers and documents structurally, key order and spelling aside. The Ruby value goes in as a JSON literal, and the adapters without such a type refuse it from JsonLiteral when the SQL is written, which is when the adapter is known.
A string against dig_text, and anything the block itself built -- a column, a function, another dug value -- go through untouched.
Arithmetic and the bit operators are refused outright on both sides:
dig_text(:n) + 1 is 6 on SQLite, an error on PostgreSQL and 6.0 on
MariaDB, and an expression on the right does not change what the
dug side is.
Instance Method Summary collapse
- #between?(min, max) ⇒ Boolean
- #in?(values) ⇒ Boolean
- #not_between?(min, max) ⇒ Boolean
- #not_in?(values) ⇒ Boolean
- #~ ⇒ Object
Instance Method Details
#between?(min, max) ⇒ Boolean
699 |
# File 'lib/active_record/refined/ast.rb', line 699 def between?(min, max) = super(comparison_value(min), comparison_value(max)) |
#in?(values) ⇒ Boolean
697 |
# File 'lib/active_record/refined/ast.rb', line 697 def in?(values) = super(comparison_set(values)) |
#not_between?(min, max) ⇒ Boolean
700 |
# File 'lib/active_record/refined/ast.rb', line 700 def not_between?(min, max) = super(comparison_value(min), comparison_value(max)) |
#not_in?(values) ⇒ Boolean
698 |
# File 'lib/active_record/refined/ast.rb', line 698 def not_in?(values) = super(comparison_set(values)) |
#~ ⇒ Object
708 709 710 |
# File 'lib/active_record/refined/ast.rb', line 708 def ~ raise ArgumentError, arithmetic_refusal(:~) end |