Class: ActiveRecord::Type::Spanner::SpannerActiveRecordConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/type/spanner/spanner_active_record_converter.rb

Class Method Summary collapse

Class Method Details

.convert_active_model_type_to_spanner(type) ⇒ Object

Converts an ActiveModel::Type to a Spanner type code.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_record/type/spanner/spanner_active_record_converter.rb', line 25

def self.convert_active_model_type_to_spanner type # rubocop:disable Metrics/CyclomaticComplexity
  # Unwrap the underlying object if the type is a DelegateClass.
  type = type.__getobj__ if type.respond_to? :__getobj__

  case type
  when NilClass then nil
  when ActiveModel::Type::Integer, ActiveModel::Type::BigInteger then :INT64
  when ActiveModel::Type::Boolean then :BOOL
  when ActiveModel::Type::String, ActiveModel::Type::ImmutableString then :STRING
  when ActiveModel::Type::Binary, ActiveRecord::Type::Spanner::Bytes then :BYTES
  when ActiveModel::Type::Float then :FLOAT64
  when ActiveModel::Type::Decimal then :NUMERIC
  when ActiveModel::Type::DateTime, ActiveModel::Type::Time, ActiveRecord::Type::Spanner::Time then :TIMESTAMP
  when ActiveModel::Type::Date then :DATE
  when ActiveRecord::Type::Json then :JSON
  when ActiveRecord::Type::Spanner::Array then [convert_active_model_type_to_spanner(type.element_type)]
  end
end

.serialize_with_transaction_isolation_level(type, value, isolation_level) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/active_record/type/spanner/spanner_active_record_converter.rb', line 13

def self.serialize_with_transaction_isolation_level type, value, isolation_level
  if type.respond_to? :serialize_with_isolation_level
    type.serialize_with_isolation_level value, isolation_level
  elsif type.respond_to? :serialize
    type.serialize value
  else
    value
  end
end