Module: Eaco::Adapters::ActiveRecord::Compatibility::V40

Defined in:
lib/eaco/adapters/active_record/compatibility/v40.rb

Overview

Rails v4.0.X compatibility layer for jsonb

Defined Under Namespace

Modules: Column

Class Method Summary collapse

Class Method Details

.included(base)

This method returns an undefined value.

Sets up the OID Type Map, reloads it, hacks native database types, and makes jsonb mimick itself as a json - for the rest of the AR machinery to work intact.

Parameters:

  • base (Class)

    the ActiveRecord model to mangle


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eaco/adapters/active_record/compatibility/v40.rb', line 19

def self.included(base)
  adapter = base.connection

  adapter.class::OID.register_type 'jsonb', adapter.class::OID::Json.new
  adapter.send :reload_type_map

  adapter.native_database_types.update(jsonb: {name: 'jsonb'})

  adapter.class.parent::PostgreSQLColumn.instance_eval do
    include Column
  end

  base.extend Scoped
end