Sha256: cfc40942ac9044c4a6c6160a645ca283c9a57edbb2c4b4e9470400529d2375c1
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
module ROM module SQL # Type-specific methods # # @api public module TypeExtensions class << self # Gets extensions for a type # # @param [Dry::Types::Type] type # # @return [Hash] # # @api public def [](wrapped) type = wrapped.optional? ? wrapped.right : wrapped @types[type.meta[:database]][type.meta[:db_type]] || EMPTY_HASH end # 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 def register(type, &block) extensions = @types[type.meta[:database]] db_type = type.meta[:db_type] raise ArgumentError, "Type #{ db_type } already registered" if extensions.key?(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] = functions end end @types = ::Hash.new do |hash, database| hash[database] = {} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rom-sql-2.0.0.beta3 | lib/rom/sql/type_extensions.rb |