Sha256: 308d0d9ac89dee4db382b3bcd4bd8086393f5ccb2999177f7289563480dea8cf

Contents?: true

Size: 714 Bytes

Versions: 2

Compression:

Stored size: 714 Bytes

Contents

# frozen_string_literal: true
require "mobility/active_model/backend_resetter"

module Mobility
  module ActiveRecord
=begin

Backend resetter for ActiveRecord models. Adds hook on +reload+ event to
{Mobility::ActiveModel::BackendResetter}.

=end
    class BackendResetter < Mobility::ActiveModel::BackendResetter

      # @param [Class] model_class Class of model to which backend resetter will be applied
      def included(model_class)
        model_reset_method = @model_reset_method

        mod = Module.new do
          define_method :reload do |*args|
            super(*args).tap { instance_eval(&model_reset_method) }
          end
        end
        model_class.include mod
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.5.1 lib/mobility/active_record/backend_resetter.rb
mobility-0.5.0 lib/mobility/active_record/backend_resetter.rb