Sha256: dbde0c6fcbcaed108f2e123f98d1429d8a0de28284a3ca89ce2fe87480b63c5f
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 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 [](type) unwrapped = type.optional? ? type.right : type @types[unwrapped.pristine] || 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) raise ArgumentError, "Type #{ type } already registered" if @types.key?(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) } @types[type] = functions end end @types = {} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rom-sql-2.0.0.beta2 | lib/rom/sql/type_extensions.rb |
rom-sql-2.0.0.beta1 | lib/rom/sql/type_extensions.rb |