Module: ROM::SQL::Attribute::TypeExtensions
- Defined in:
- lib/rom/sql/attribute.rb
Overview
Type-specific methods
Class Method Summary collapse
-
.[](wrapped) ⇒ Hash
Gets extensions for a type.
-
.register(type, &block) ⇒ Object
Registers a set of operations supported for a specific type.
Class Method Details
.[](wrapped) ⇒ Hash
Gets extensions for a type
31 32 33 34 35 |
# File 'lib/rom/sql/attribute.rb', line 31 def [](wrapped) type = wrapped.default? ? wrapped.type : wrapped type = type.optional? ? type.right : type @types[type.[:database]][type.[:db_type]] || EMPTY_HASH end |
.register(type, &block) ⇒ Object
Registers a set of operations supported for a specific type
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rom/sql/attribute.rb', line 49 def register(type, &block) extensions = @types[type.[:database]] db_type = type.[:db_type] 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) } extensions[db_type] = functions end |