Module: ActiveRecord::Refined::AST::JsonComparable

Included in:
JsonPath
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 gives text on every adapter, and what a text value compared with a number means is a question the three answer three ways: dig(:n) == 5 is true on SQLite, an error on PostgreSQL and true on MySQL, while dig(:flag) == true is true, an error, and false. cast is what says which type was meant, and then all three agree.

dig_json is refused the other way about: the JSON for a string carries its quotes, so dig_json(:name) == 'alice' is false on SQLite, an error on PostgreSQL and true on MySQL. dig is the one that gives the value.

A string against dig, and anything the block itself built -- a column, a function, another dug value -- go through untouched.

Instance Method Summary collapse

Instance Method Details

#between?(min, max) ⇒ Boolean

Returns:

  • (Boolean)


540
# File 'lib/active_record/refined/ast.rb', line 540

def between?(min, max) = super(*check_each([min, max]))

#in?(values) ⇒ Boolean

Returns:

  • (Boolean)


538
# File 'lib/active_record/refined/ast.rb', line 538

def in?(values) = super(check_each(values))

#not_between?(min, max) ⇒ Boolean

Returns:

  • (Boolean)


541
# File 'lib/active_record/refined/ast.rb', line 541

def not_between?(min, max) = super(*check_each([min, max]))

#not_in?(values) ⇒ Boolean

Returns:

  • (Boolean)


539
# File 'lib/active_record/refined/ast.rb', line 539

def not_in?(values) = super(check_each(values))