Module: ActiveRecord::Refined::AST::JsonComparable
- Included in:
- JsonExcept, 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 is refused the other way about: the JSON for a string carries
its quotes, so dig(:name) == 'alice' is false on SQLite, an
error on PostgreSQL and true on MySQL. dig_text is the one that
gives the value. What bury and except give back is JSON as dig's
is, and is refused the same way.
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
547 |
# File 'lib/active_record/refined/ast.rb', line 547 def between?(min, max) = super(*check_each([min, max])) |
#in?(values) ⇒ Boolean
545 |
# File 'lib/active_record/refined/ast.rb', line 545 def in?(values) = super(check_each(values)) |
#not_between?(min, max) ⇒ Boolean
548 |
# File 'lib/active_record/refined/ast.rb', line 548 def not_between?(min, max) = super(*check_each([min, max])) |
#not_in?(values) ⇒ Boolean
546 |
# File 'lib/active_record/refined/ast.rb', line 546 def not_in?(values) = super(check_each(values)) |
#~ ⇒ Object
556 557 558 |
# File 'lib/active_record/refined/ast.rb', line 556 def ~ raise ArgumentError, arithmetic_refusal(:~) end |