Module: Hanami::Model::Sql::Types::Schema

Defined in:
lib/hanami/model/sql/types.rb,
lib/hanami/model/sql/types/schema/coercions.rb

Overview

Types for schema definitions

Since:

  • 0.7.0

Defined Under Namespace

Modules: Coercions Classes: AssociationType

Constant Summary collapse

String =

Since:

  • 0.7.0

Types::Optional::Coercible::String
Int =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Int.constructor(Coercions.method(:int))
Float =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Float.constructor(Coercions.method(:float))
Decimal =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Float.constructor(Coercions.method(:decimal))
Bool =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Strict::Bool
Date =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Date.constructor(Coercions.method(:date))
DateTime =

Since:

  • 0.7.0

Types::Strict::Nil | Types::DateTime.constructor(Coercions.method(:datetime))
Time =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Time.constructor(Coercions.method(:time))
Array =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Array.constructor(Coercions.method(:array))
Hash =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Hash.constructor(Coercions.method(:hash))
PG_JSON =

Since:

  • 0.7.0

Types::Strict::Nil | Types::Any.constructor(Coercions.method(:pg_json))
MAPPING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.7.0

{
  Types::String.pristine => Schema::String,
  Types::Int.pristine => Schema::Int,
  Types::Float.pristine => Schema::Float,
  Types::Decimal.pristine => Schema::Decimal,
  Types::Bool.pristine => Schema::Bool,
  Types::Date.pristine => Schema::Date,
  Types::DateTime.pristine => Schema::DateTime,
  Types::Time.pristine => Schema::Time,
  Types::Array.pristine => Schema::Array,
  Types::Hash.pristine => Schema::Hash,
  Types::String.optional.pristine => Schema::String,
  Types::Int.optional.pristine => Schema::Int,
  Types::Float.optional.pristine => Schema::Float,
  Types::Decimal.optional.pristine => Schema::Decimal,
  Types::Bool.optional.pristine => Schema::Bool,
  Types::Date.optional.pristine => Schema::Date,
  Types::DateTime.optional.pristine => Schema::DateTime,
  Types::Time.optional.pristine => Schema::Time,
  Types::Array.optional.pristine => Schema::Array,
  Types::Hash.optional.pristine => Schema::Hash
}.freeze

Class Method Summary collapse

Class Method Details

.coercible(attribute) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert given type into coercible

Since:

  • 0.7.0



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/hanami/model/sql/types.rb', line 67

def self.coercible(attribute)
  return attribute if attribute.constrained?

  type      = attribute.type
  unwrapped = type.optional? ? type.right : type

  # NOTE: In the future rom-sql should be able to always return Ruby
  # types instead of Sequel types. When that will happen we can get
  # rid of this logic in the block and fall back to:
  #
  #  MAPPING.fetch(unwrapped.pristine, attribute)
  MAPPING.fetch(unwrapped.pristine) do
    if pg_json?(unwrapped.pristine)
      Schema::PG_JSON
    else
      attribute
    end
  end
end

.pg_json_pristinesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.4



89
90
91
92
93
# File 'lib/hanami/model/sql/types.rb', line 89

def self.pg_json_pristines
  @pg_json_pristines ||= ::Hash.new do |hash, type|
    hash[type] = (ROM::SQL::Types::PG.const_get(type).pristine if defined?(ROM::SQL::Types::PG))
  end
end