Module: AssociateJsonb

Defined in:
lib/associate_jsonb.rb,
lib/associate_jsonb/version.rb,
lib/associate_jsonb/reflection.rb,
lib/associate_jsonb/persistence.rb,
lib/associate_jsonb/attribute_methods.rb,
lib/associate_jsonb/predicate_builder.rb,
lib/associate_jsonb/connection_adapters.rb,
lib/associate_jsonb/with_store_attribute.rb,
lib/associate_jsonb/arel_extensions/table.rb,
lib/associate_jsonb/relation/where_clause.rb,
lib/associate_jsonb/attribute_methods/read.rb,
lib/associate_jsonb/supported_rails_version.rb,
lib/associate_jsonb/associations/association.rb,
lib/associate_jsonb/arel_nodes/jsonb/at_arrow.rb,
lib/associate_jsonb/arel_nodes/jsonb/operator.rb,
lib/associate_jsonb/arel_nodes/jsonb/attribute.rb,
lib/associate_jsonb/associations/alias_tracker.rb,
lib/associate_jsonb/arel_nodes/jsonb/dash_arrow.rb,
lib/associate_jsonb/arel_nodes/jsonb/hash_arrow.rb,
lib/associate_jsonb/arel_extensions/nodes/binary.rb,
lib/associate_jsonb/arel_nodes/jsonb/double_pipe.rb,
lib/associate_jsonb/arel_nodes/sql_casted_binary.rb,
lib/associate_jsonb/associations/builder/has_one.rb,
lib/associate_jsonb/associations/join_dependency.rb,
lib/associate_jsonb/associations/builder/has_many.rb,
lib/associate_jsonb/arel_nodes/sql_casted_equality.rb,
lib/associate_jsonb/associations/association_scope.rb,
lib/associate_jsonb/associations/builder/belongs_to.rb,
lib/associate_jsonb/arel_extensions/visitors/visitor.rb,
lib/associate_jsonb/associations/foreign_association.rb,
lib/associate_jsonb/arel_extensions/nodes/table_alias.rb,
lib/associate_jsonb/associations/has_many_association.rb,
lib/associate_jsonb/arel_nodes/jsonb/bindable_operator.rb,
lib/associate_jsonb/arel_nodes/jsonb/dash_double_arrow.rb,
lib/associate_jsonb/associations/preloader/association.rb,
lib/associate_jsonb/arel_extensions/visitors/postgresql.rb,
lib/associate_jsonb/associations/belongs_to_association.rb,
lib/associate_jsonb/connection_adapters/schema_creation.rb,
lib/associate_jsonb/associations/conflicting_association.rb,
lib/associate_jsonb/connection_adapters/schema_statements.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/table.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/alter_table.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/table_definition.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/reference_definition.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/constraint_definition.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/add_jsonb_nested_set_function.rb,
lib/associate_jsonb/connection_adapters/schema_definitions/add_jsonb_foreign_key_function.rb

Defined Under Namespace

Modules: ArelExtensions, ArelNodes, Associations, AttributeMethods, ConnectionAdapters, Persistence, PredicateBuilder, Reflection, Relation, WithStoreAttribute

Constant Summary collapse

VERSION =
"6.1.4.1.1"
SUPPORTED_RAILS_VERSION =
"6.1.4.1"

Class Method Summary collapse

Class Method Details

.add_hash_type(*classes) ⇒ Object

Add class(es) to the list of classes that are able to be upated when ‘jsonb_set_enabled` is true



65
66
67
# File 'lib/associate_jsonb.rb', line 65

def self.add_hash_type(*classes)
  self.jsonb_set_added |= classes.flatten
end

.disable_jsonb_set(klass = nil, *classes) ⇒ Object

Disables the use of ‘jsonb_nested_set` for hash updates

if passed a class, or a list of classes, those classes will be removed from the list of enabled classes



57
58
59
60
# File 'lib/associate_jsonb.rb', line 57

def self.disable_jsonb_set(klass = nil, *classes)
  remove_hash_type(*Array(klass), *classes) unless klass.nil?
  self.jsonb_set_enabled = false
end

.enable_jsonb_set(klass = nil, *classes) ⇒ Object

Enables the use of ‘jsonb_nested_set` for hash updates

if passed a class, or a list of classes, those classes will be added to the enabled classes. if no argument is given, and the enabled class list is empty, ‘ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb` is added to the list of enabled classes



43
44
45
46
47
48
49
50
# File 'lib/associate_jsonb.rb', line 43

def self.enable_jsonb_set(klass = nil, *classes)
  if klass.nil?
    add_hash_type jsonb_oid_class if jsonb_hash_types.empty?
  else
    add_hash_type(*Array(klass), *classes)
  end
  self.jsonb_set_enabled = true
end

.is_hash?(value) ⇒ Boolean

Returns true if the given value is a descendant of any of the classes in ‘jsonb_hash_types`

Returns:

  • (Boolean)


86
87
88
# File 'lib/associate_jsonb.rb', line 86

def self.is_hash?(value)
  !!value && self.jsonb_hash_types.any? { |type| value.is_a?(type) }
end

.merge_hash?(value) ⇒ Boolean

Returns true if ‘jsonb_set_enabled` is true and the value is an enabled hash type

Returns:

  • (Boolean)


79
80
81
# File 'lib/associate_jsonb.rb', line 79

def self.merge_hash?(value)
  !!jsonb_set_enabled && is_hash?(value)
end

.remove_hash_type(*classes) ⇒ Object

Remove class(es) from the list of classes that are able to be upated when ‘jsonb_set_enabled` is true



72
73
74
# File 'lib/associate_jsonb.rb', line 72

def self.remove_hash_type(*classes)
  self.jsonb_set_removed |= classes.flatten
end