Class: Refinery::Activity
- Inherits:
-
Object
- Object
- Refinery::Activity
- Defined in:
- lib/refinery/activity.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns a string representation of the Class name of the object which this instance is recording.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#created_image ⇒ Object
Image asset to use to represent newly created instances of the class this activity represents.
-
#limit ⇒ Object
Total number of activies to show for a given class of activity.
-
#nested_with ⇒ Object
Returns the value of attribute nested_with.
-
#order ⇒ Object
SQL order by string to specify how to order the activities in the activity feed for the given activities class.
-
#title ⇒ Object
The title to be displayed for each item of this activity.
-
#updated_image ⇒ Object
Image asset to use to represent updated instance of the class thisa activity represents.
- #url ⇒ Object
- #url_prefix ⇒ Object
Instance Method Summary collapse
-
#base_class_name ⇒ Object
- Returns a string containing the base class name (everything to the right of the last
-
in the class definition) of the Class this instance is recording.
-
#initialize(options = {}) ⇒ Activity
constructor
Creates a new instance of Activity for a registered Refinery Plugin.
-
#klass ⇒ Object
Returns the Class Constant for the Class which this instance is recording.
-
#nesting(record_string = "record") ⇒ Object
to use in a URL like edit_refinery_admin_group_individuals_path(record.group, record) which will help you if you’re using nested routed.
Constructor Details
#initialize(options = {}) ⇒ Activity
Creates a new instance of Activity for a registered Refinery Plugin. An optional hash of options can be specified to customize the values of each attribute accessor defined on this class. Each key specified in the options hash should be a symbol representation of the accessor name you wish to customize the value for.
Example:
To override the limit and title of the activity:
Activity.new(:limit => 10, :title => "Newest Activity!")
Warning:
for the nested_with option, pass in the reverse order of ancestry e.g. [parent.parent_of_parent, parent]
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/refinery/activity.rb', line 35 def initialize( = {}) { :class_name => nil, :conditions => nil, :created_image => "add.png", :limit => 7, :nested_with => [], :order => "updated_at DESC", :title => "title", :updated_image => "edit.png", :url => nil, :url_prefix => "edit" }.merge().each { |key, value| self.send(:"#{key}=", value) } end |
Instance Attribute Details
#class_name ⇒ Object
Returns a string representation of the Class name of the object which this instance is recording
51 52 53 |
# File 'lib/refinery/activity.rb', line 51 def class_name @class_name end |
#conditions ⇒ Object
Returns the value of attribute conditions.
3 4 5 |
# File 'lib/refinery/activity.rb', line 3 def conditions @conditions end |
#created_image ⇒ Object
Image asset to use to represent newly created instances of the class this activity represents
7 8 9 |
# File 'lib/refinery/activity.rb', line 7 def created_image @created_image end |
#limit ⇒ Object
Total number of activies to show for a given class of activity
10 11 12 |
# File 'lib/refinery/activity.rb', line 10 def limit @limit end |
#nested_with ⇒ Object
Returns the value of attribute nested_with.
12 13 14 |
# File 'lib/refinery/activity.rb', line 12 def nested_with @nested_with end |
#order ⇒ Object
SQL order by string to specify how to order the activities in the activity feed for the given activities class
16 17 18 |
# File 'lib/refinery/activity.rb', line 16 def order @order end |
#title ⇒ Object
The title to be displayed for each item of this activity
19 20 21 |
# File 'lib/refinery/activity.rb', line 19 def title @title end |
#updated_image ⇒ Object
Image asset to use to represent updated instance of the class thisa activity represents
22 23 24 |
# File 'lib/refinery/activity.rb', line 22 def updated_image @updated_image end |
#url ⇒ Object
98 99 100 |
# File 'lib/refinery/activity.rb', line 98 def url @url ||= "refinery.#{url_prefix}#{Refinery.route_for_model(klass)}" end |
#url_prefix ⇒ Object
92 93 94 |
# File 'lib/refinery/activity.rb', line 92 def url_prefix "#{"#{@url_prefix}_".gsub("__", "_") if @url_prefix.present?}" end |
Instance Method Details
#base_class_name ⇒ Object
- Returns a string containing the base class name (everything to the right of the last
-
in the class definition)
of the Class this instance is recording
Example:
Given: Activity.new(:class_name => "Refinery::Image")
activity.base_class_name => "Image"
70 71 72 |
# File 'lib/refinery/activity.rb', line 70 def base_class_name self.klass.name.demodulize end |
#klass ⇒ Object
Returns the Class Constant for the Class which this instance is recording
Example:
activity.klass => Refinery::Image
78 79 80 |
# File 'lib/refinery/activity.rb', line 78 def klass self.class_name.constantize end |
#nesting(record_string = "record") ⇒ Object
to use in a URL like edit_refinery_admin_group_individuals_path(record.group, record) which will help you if you’re using nested routed.
84 85 86 87 88 |
# File 'lib/refinery/activity.rb', line 84 def nesting(record_string = "record") self.nested_with.inject("") { |nest_chain, nesting| nest_chain << "#{record_string}.#{nesting}," } end |