Module: ActiveUUID::Patches::PostgreSQLQuoting

Extended by:
ActiveSupport::Concern
Defined in:
lib/activeuuid/patches.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(_klass) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/activeuuid/patches.rb', line 147

def self.prepended(_klass)
  def quote(value, column = nil)
    value = UUIDTools::UUID.serialize(value) if column&.type == :uuid
    value = value.to_s if value.is_a? UUIDTools::UUID
    case method(__method__).super_method.arity
    when 1 then super(value)
    else super
    end
  end

  def type_cast(value, column = nil, *args)
    value = UUIDTools::UUID.serialize(value) if column&.type == :uuid
    value = value.to_s if value.is_a? UUIDTools::UUID
    super
  end

  def native_database_types
    super.merge(uuid: { name: "uuid" })
  end
end

Instance Method Details

#native_database_typesObject



163
164
165
# File 'lib/activeuuid/patches.rb', line 163

def native_database_types
  super.merge(uuid: { name: "uuid" })
end

#quote(value, column = nil) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/activeuuid/patches.rb', line 148

def quote(value, column = nil)
  value = UUIDTools::UUID.serialize(value) if column&.type == :uuid
  value = value.to_s if value.is_a? UUIDTools::UUID
  case method(__method__).super_method.arity
  when 1 then super(value)
  else super
  end
end

#type_cast(value, column = nil, *args) ⇒ Object



157
158
159
160
161
# File 'lib/activeuuid/patches.rb', line 157

def type_cast(value, column = nil, *args)
  value = UUIDTools::UUID.serialize(value) if column&.type == :uuid
  value = value.to_s if value.is_a? UUIDTools::UUID
  super
end