module ROM::SQL::TypeExtensions
Type-specific methods
@api public
Public Class Methods
[](type)
click to toggle source
Gets extensions for a type
@param type [Dry::Types::Type] wrapped
@return [Hash]
@api public
# File lib/rom/sql/type_extensions.rb, line 17 def [](type) @types[type.meta[:database]][type.meta[:db_type]] || EMPTY_HASH end
register(type, &block)
click to toggle source
Registers a set of operations supported for a specific type
@example
ROM::SQL::Attribute::TypeExtensions.register(ROM::SQL::Types::PG::JSONB) do def contain(type, expr, keys) Attribute[Types::Bool].meta(sql_expr: expr.pg_jsonb.contains(value)) end end
@param [Dry::Types::Type] type Type
@api public
# File lib/rom/sql/type_extensions.rb, line 33 def register(type, &block) extensions = @types[type.meta[:database]] db_type = type.meta[:db_type] mod = Module.new(&block) ctx = Object.new.extend(mod) functions = mod.public_instance_methods.each_with_object({}) { |m, ms| ms[m] = ctx.method(m) } extensions[db_type] = (extensions[db_type] || {}).merge(functions) end