Class: ActiveRecord::Refined::AST::JsonBuild
- Includes:
- ComputedJson, JsonComparable, Predications
- Defined in:
- lib/active_record/refined/ast.rb
Overview
A JSON document built in the row: json_array from the values given, json_object from a Ruby hash. SQLite and the MySQL family both say the standard names; PostgreSQL is asked to build jsonb, whose documents the other JSON operations here read.
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(kind, values) ⇒ JsonBuild
constructor
A new instance of JsonBuild.
- #to_arel(table, model) ⇒ Object
Methods included from ComputedJson
Methods included from JsonComparable
#between?, #in?, #not_between?, #not_in?, #~
Methods included from Predications
#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when
Methods inherited from Node
Constructor Details
#initialize(kind, values) ⇒ JsonBuild
Returns a new instance of JsonBuild.
1190 1191 1192 1193 |
# File 'lib/active_record/refined/ast.rb', line 1190 def initialize(kind, values) @kind = kind @values = kind == :object ? check_pairs(values) : values end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
1188 1189 1190 |
# File 'lib/active_record/refined/ast.rb', line 1188 def kind @kind end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
1188 1189 1190 |
# File 'lib/active_record/refined/ast.rb', line 1188 def values @values end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'lib/active_record/refined/ast.rb', line 1195 def to_arel(table, model) dialect = Dialect.for(model) if kind == :array dialect.json_build(:array, nil, values.map { |value| build_argument(value, dialect, table, model) }, model) else dialect.json_build(:object, values.keys.map(&:to_s), values.values.map { |value| build_argument(value, dialect, table, model) }, model) end end |