Module: Redmine::Acts::ActivityProvider::ClassMethods

Defined in:
lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_activity_provider(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb', line 28

def acts_as_activity_provider(options = {})
  unless self.included_modules.include?(Redmine::Acts::ActivityProvider::InstanceMethods)
    cattr_accessor :activity_provider_options
    send :include, Redmine::Acts::ActivityProvider::InstanceMethods
  end

  options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :scope)
  self.activity_provider_options ||= {}

  # One model can provide different event types
  # We store these options in activity_provider_options hash
  event_type = options.delete(:type) || self.name.underscore.pluralize

  options[:timestamp] ||= "#{table_name}.created_on"
  options[:author_key] = "#{table_name}.#{options[:author_key]}" if options[:author_key].is_a?(Symbol)
  self.activity_provider_options[event_type] = options
end