Sha256: bfdd0e9dc4638e9e13138bc6e8fe0c59c963f061fad595be84efefcd0ea0955b

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Ohm
  # The following is an example usage of this plugin:
  #
  #   class Post < Ohm::Model
  #     include Ohm::Callbacks
  #
  #   protected
  #     def before_create
  #       # sanitize the decimal values here
  #     end
  #
  #     def before_save
  #       # do something here
  #     end
  #
  #     def after_create
  #       # do twitter posting here
  #     end
  #
  #     def after_save
  #       # do something with the ids
  #     end
  #   end
  module Callbacks
    def save
      is_new = new?

      before_create if is_new
      before_update if not is_new
      before_save

      result = super

      after_create if is_new
      after_update if not is_new
      after_save

      return result
    end

    def delete
      before_delete
      result = super
      after_delete

      return result
    end

  protected
    def before_save
    end

    def after_save
    end

    def before_create
    end

    def after_create
    end

    def before_update
    end

    def after_update
    end

    def before_delete
    end

    def after_delete
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ohm-contrib-3.0.0 lib/ohm/callbacks.rb
ohm-contrib-2.2.0 lib/ohm/callbacks.rb
ohm-contrib-2.0.1 lib/ohm/callbacks.rb
ohm-contrib-2.0.0 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.rc2 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.rc1 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.alpha5 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.alpha4 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.alpha3 lib/ohm/callbacks.rb
ohm-contrib-2.0.0.alpha2 lib/ohm/callbacks.rb