Sha256: e27490bde427819d1157a8d573ae92ca9840b4027d2e84ccb26ae1b081c8faeb
Contents?: true
Size: 1.23 KB
Versions: 7
Compression:
Stored size: 1.23 KB
Contents
module Decanter module Extensions def self.included(base) base.extend(ClassMethods) end def decant_update(args, **options) self.attributes = self.class.decant(args, options) self.save(context: options[:context]) end def decant_update!(args, **options) self.attributes = self.class.decant(args, options) self.save!(context: options[:context]) end def decant(args, **options) self.class.decant(args, options) end module ClassMethods def decant_create(args, **options) self.new(decant(args, options)) .save(context: options[:context]) end def decant_new(args, **options) self.new(decant(args, options)) end def decant_create!(args, **options) self.new(decant(args, options)) .save!(context: options[:context]) end def decant(args, options = {}) if (specified_decanter = options[:decanter]) Decanter.decanter_from(specified_decanter) else Decanter.decanter_for(self) end.decant(args) end end module ActiveRecordExtensions def self.enable! ::ActiveRecord::Base.include(Decanter::Extensions) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems