Class: ActiveRecordExtended::QueryMethods::Json::JsonChain

Inherits:
Object
  • Object
show all
Includes:
Utilities::OrderBy, Utilities::Support
Defined in:
lib/active_record_extended/query_methods/json.rb

Constant Summary collapse

DEFAULT_ALIAS =
'"results"'
TO_JSONB_OPTIONS =
[:array_agg, :distinct, :to_jsonb].to_set.freeze
ARRAY_OPTIONS =
[:array, true].freeze

Constants included from Utilities::Support

Utilities::Support::A_TO_Z_KEYS

Instance Method Summary collapse

Methods included from Utilities::OrderBy

#inline_order_by, #order_by_expression, #process_ordering_arguments!, #scope_preprocess_order_args, #to_ordered_table_path

Methods included from Utilities::Support

#double_quote, #flatten_safely, #flatten_to_sql, #from_clause_constructor, #generate_grouping, #generate_named_function, #group_when_needed, #key_generator, #literal_key, #needs_to_be_grouped?, #nested_alias_escape, #pipe_cte_with!, #to_arel_sql, #wrap_with_agg_array, #wrap_with_array

Constructor Details

#initialize(scope) ⇒ JsonChain

Returns a new instance of JsonChain.



22
23
24
# File 'lib/active_record_extended/query_methods/json.rb', line 22

def initialize(scope)
  @scope = scope
end

Instance Method Details

#json_build_literal!(*args) ⇒ Object



41
42
43
44
# File 'lib/active_record_extended/query_methods/json.rb', line 41

def json_build_literal!(*args)
  options = json_object_options(args, only: [:values, :col_alias])
  build_json_literal(Arel::Nodes::JsonBuildObject, **options)
end

#json_build_object!(*args) ⇒ Object



31
32
33
34
# File 'lib/active_record_extended/query_methods/json.rb', line 31

def json_build_object!(*args)
  options = json_object_options(args, except: [:values, :cast_with, :order_by])
  build_json_object(Arel::Nodes::JsonBuildObject, **options)
end

#jsonb_build_literal!(*args) ⇒ Object



46
47
48
49
# File 'lib/active_record_extended/query_methods/json.rb', line 46

def jsonb_build_literal!(*args)
  options = json_object_options(args, only: [:values, :col_alias])
  build_json_literal(Arel::Nodes::JsonbBuildObject, **options)
end

#jsonb_build_object!(*args) ⇒ Object



36
37
38
39
# File 'lib/active_record_extended/query_methods/json.rb', line 36

def jsonb_build_object!(*args)
  options = json_object_options(args, except: [:values, :cast_with, :order_by])
  build_json_object(Arel::Nodes::JsonbBuildObject, **options)
end

#row_to_json!(**args, &block) ⇒ Object



26
27
28
29
# File 'lib/active_record_extended/query_methods/json.rb', line 26

def row_to_json!(**args, &block)
  options = json_object_options(args, except: [:values, :value])
  build_row_to_json(**options, &block)
end