Module: Feedable::ActsAsFeedable::ActMethod
- Defined in:
- lib/feedable/acts_as_feedable.rb
Instance Method Summary collapse
-
#acts_as_feedable(options = {}) ⇒ Object
Configuration options are:.
Instance Method Details
#acts_as_feedable(options = {}) ⇒ Object
Configuration options are:
-
target_name
- specifies how to get the name of the target (used by the view to store the name of the primary object the feed links to). (default is nil) -
scoping_object?
- Boolean - If true, this object will become the scoping object for all feedables descending from it. eg. a Project is a scoping object for all discussions, comments, and writeboards within the project. -
parent
- Specifies the code to execute to traverse up the feedable chain in search of any scoping objects
Delegate Options
-
actions
- overrides the :created, :updated, and :destroyed actions with custom actions (must be set if thedelegate
option is used) -
references
- provides feeds with a surrogate feedable when the object itself isn’t the focus of the feed. (must be set if thedelegate
option is used)
Aggregate Options
-
action
- specifies the action group the aggregate feed should belong to (must be set if theaggregate
option is used) -
references
- provides aggregate feeds with a feedable by which to group this object’s feeds. (must be set if theaggregate
option is used) -
component_reference
- specifies the object that is referenced by the aggregated feed component. This needs to be the object that the feed “happens to” (e.g. a label is applied to an item). We use this when determining how to handle subsequent update and destroy actions. (aggregated feed components are used to store each action that is referenced by an aggregate feed) (default is self) -
component_secondary_reference
- specifies an optional secondary object that is referenced by an aggregated feed component. For example, the item that a label is being applied to (default is nil) -
component_reference_name
- specifies how to get the name of the reference (used when a component is destroyed). (default is component_reference.name) -
component_secondary_reference_name
- specifies how to get the name of the secondary_reference (used when the secondary_reference is destroyed). (default is component_secondary_reference.name)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/feedable/acts_as_feedable.rb', line 23 def acts_as_feedable( = {}) extend ClassMethods unless (class << self; included_modules; end).include?(ClassMethods) include InstanceMethods unless included_modules.include?(InstanceMethods) # Sanity Check .assert_valid_keys(:scoping_object?, :parent, :target_name, :delegate, :aggregate) [:delegate].assert_valid_keys(:actions, :references) if [:delegate].present? raise 'actions option must be set if the delegate option is used' if [:delegate].is_a?(Hash) && [:delegate][:actions].blank? raise 'references option must be set if the delegate option is used' if [:delegate].is_a?(Hash) && [:delegate][:references].blank? [:aggregate].assert_valid_keys(:action, :references, :component_reference, :component_secondary_reference, :component_reference_name, :component_secondary_reference_name) if [:aggregate].present? raise 'action option must be set if the aggregate option is used' if [:aggregate].is_a?(Hash) && [:aggregate][:action].blank? raise 'references option must be set if the aggregate option is used' if [:aggregate].is_a?(Hash) && [:aggregate][:references].blank? .reverse_merge!(:delegate => {}, :aggregate => {}) self. = class_eval " \n def feedable\n if delegating?\n \#{options[:delegate][:references]}\n elsif aggregating?\n \#{options[:aggregate][:references]}\n else\n self\n end\n end\n \n def target_name\n \#{options[:target_name] || 'nil'}\n end\n\n def parent_feedable\n \#{options[:parent] || 'nil'}\n end\n \n # Aggregate Feed Methods\n \n def component_reference\n \#{options[:aggregate][:component_reference] || 'self'}\n end\n \n def component_reference_name\n \#{options[:aggregate][:component_reference_name] || 'component_reference.name'}\n end\n \n def component_secondary_reference\n \#{options[:aggregate][:component_secondary_reference] || 'nil'}\n end\n \n def component_secondary_reference_name\n \#{options[:aggregate][:component_secondary_reference_name] || 'component_secondary_reference.try(:name)'}\n end\n # END Aggregate Feed Methods\n EOV\n \nend\n" |