Module: Sequel::Plugins::PgTypecastOnLoad::ClassMethods
- Defined in:
- lib/sequel/plugins/pg_typecast_on_load.rb
Instance Attribute Summary collapse
-
#pg_typecast_on_load_columns ⇒ Object
readonly
The columns to typecast on load for this model.
Instance Method Summary collapse
-
#add_pg_typecast_on_load_columns(*columns) ⇒ Object
Add additional columns to typecast on load for this model.
- #call(values) ⇒ Object
-
#load_typecast_pg(values) ⇒ Object
Lookup the conversion proc for the column’s oid in the Database object, and use it to convert the value.
Instance Attribute Details
#pg_typecast_on_load_columns ⇒ Object (readonly)
The columns to typecast on load for this model.
41 42 43 |
# File 'lib/sequel/plugins/pg_typecast_on_load.rb', line 41 def pg_typecast_on_load_columns @pg_typecast_on_load_columns end |
Instance Method Details
#add_pg_typecast_on_load_columns(*columns) ⇒ Object
Add additional columns to typecast on load for this model.
44 45 46 |
# File 'lib/sequel/plugins/pg_typecast_on_load.rb', line 44 def add_pg_typecast_on_load_columns(*columns) @pg_typecast_on_load_columns.concat(columns) end |
#call(values) ⇒ Object
48 49 50 |
# File 'lib/sequel/plugins/pg_typecast_on_load.rb', line 48 def call(values) super(load_typecast_pg(values)) end |
#load_typecast_pg(values) ⇒ Object
Lookup the conversion proc for the column’s oid in the Database object, and use it to convert the value.
54 55 56 57 58 59 60 61 |
# File 'lib/sequel/plugins/pg_typecast_on_load.rb', line 54 def load_typecast_pg(values) pg_typecast_on_load_columns.each do |c| if (v = values[c]).is_a?(String) && (oid = db_schema[c][:oid]) && (pr = db.conversion_procs[oid]) values[c] = pr.call(v) end end values end |