Sha256: 9427d949c22e73d1508f41d10f7a9db0df9b35566cec2a641ab9e287f95be1ca

Contents?: true

Size: 826 Bytes

Versions: 10

Compression:

Stored size: 826 Bytes

Contents

module Spontaneous
  module DataMapper
    module ContentModel
      module InstanceHooks
        # This only currently supports the after_save hooks as that's the
        # only one that's used (by PagePieces to save their owner after
        # a style change)
        def after_save_hook(&block)
          add_instance_hook(:after_save, &block)
        end

        def after_save
          run_after_instance_hooks(:after_save)
          super
        end

        private

        def add_instance_hook(hook, &block)
          instance_hooks(hook).push(block)
        end

        def instance_hooks(hook)
          @instance_hooks ||= {}
          @instance_hooks[hook] ||= []
        end

        def run_after_instance_hooks(hook)
          instance_hooks(hook).each{|b| b.call}
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta9 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta8 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta7 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta6 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta5 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta4 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta3 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta2 lib/spontaneous/data_mapper/content_model/instance_hooks.rb
spontaneous-0.2.0.beta1 lib/spontaneous/data_mapper/content_model/instance_hooks.rb