Sha256: 8553e70d5a4ae89bd3de0bf28ce3ebbb3bfe9eb2a87e1e5d56f8254852fdca72
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module TrxExt module ObjectExt # Wraps specified method in an +ActiveRecord+ transaction. # # @example # class Tilapia < Symbology::Base # wrap_in_trx def gnosis(number) # introspect(number, string.numerology(:kabbalah).sum) # end # end # # order = Tilapia.new # order.gnosis(93) # # (0.6ms) BEGIN # # Introspection Load (0.4ms) SELECT "introspections".* FROM "introspections" WHERE "introspections"."id" = $1 LIMIT 1 [["id", 93]] # # (0.2ms) COMMIT # # => 418 # # @param method [Symbol] a name of the method # @return [Symbol] def wrap_in_trx(method) module_to_prepend = Module.new do class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{method}(...) trx do super end end RUBY end prepend module_to_prepend method end # A shorthand version of <tt>ActiveRecord::Base.transaction</tt> def trx(...) ActiveRecord::Base.transaction(...) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
trx_ext-1.0.2 | lib/trx_ext/object_ext.rb |
trx_ext-1.0.1 | lib/trx_ext/object_ext.rb |
trx_ext-1.0.0 | lib/trx_ext/object_ext.rb |