Sha256: 59d4ca1e605fc5dd867519edc3f9d88ae4b9533c5771a6b2470474467c370b5e

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

class Eventable::EventableController < ApplicationController

  before_filter :try_before_callback

  # make default actions that do nothing but just execute the callback
  %w(index show new create edit update destroy).each do |action|
    define_method action do
      try_after_callback
    end
  end

  private

  # auto detected from the model that uses acts_as_event
  def event_model
    Eventable.model
  end

  # events themselves should be handled by the application
  # override to true to use the (debugging) eventscontroller from this
  # gem
  def enable_events_controller
    false
  end

  def try_before_callback
    m = "before_#{action_name}_#{controller_name}"
    send(m) if respond_to?(m)
  end


  # influence eventable controller actions below here
  # the naming scheme is (before|after)_action / after_action_fail

  def try_after_callback(failing = false)
    m = "after_#{action_name}_#{controller_name}"
    m << "_fail" if failing
    if respond_to? m
      send(m)
    else
      yield if block_given?
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dcs-eventable-0.0.8 app/controllers/eventable/eventable_controller.rb