Sha256: 06ec0521b0d2bbadb973171ce8cd957b4ed28b41f33da0321d667eec5e391050

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

class Apisync
  module ActiveRecordExtension
    def self.included(klass)
      klass.extend(ClassMethods)
      klass.include(InstanceMethods)
    end

    module InstanceMethods
      attr_accessor :apisync

      private

      def apisync_on_after_initialize
        @apisync = Apisync::Rails::Model.new(self)
        @apisync.instance_eval(&self.class.apisync_block)
      end

      def apisync_on_after_commit
        @apisync.sync
      end
    end

    module ClassMethods
      def apisync_block
        @apisync_block
      end

      def apisync(&block)
        after_initialize :apisync_on_after_initialize
        after_commit :apisync_on_after_commit

        @apisync_block = block
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apisync-rails-0.3.0 lib/apisync/active_record_extension.rb
apisync-rails-0.1.2 lib/apisync/active_record_extension.rb
apisync-rails-0.1.1 lib/apisync/active_record_extension.rb
apisync-rails-0.0.4 lib/apisync/active_record_extension.rb