Class: Refinery::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/refinery/activity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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]


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/refinery/activity.rb', line 41

def initialize(options = {})
  {
    :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",
    :use_record_in_nesting => true
  }.merge(options).each { |key, value| self.send(:"#{key}=", value) }
end

Instance Attribute Details

#class_nameObject

Returns a string representation of the Class name of the object which this instance is recording



58
59
60
# File 'lib/refinery/activity.rb', line 58

def class_name
  @class_name
end

#conditionsObject

Returns the value of attribute conditions.



3
4
5
# File 'lib/refinery/activity.rb', line 3

def conditions
  @conditions
end

#created_imageObject

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

#limitObject

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_withObject

Other objects, like parents, to include in the nesting structure



13
14
15
# File 'lib/refinery/activity.rb', line 13

def nested_with
  @nested_with
end

#orderObject

SQL order by string to specify how to order the activities in the activity feed for the given activities class



17
18
19
# File 'lib/refinery/activity.rb', line 17

def order
  @order
end

#titleObject

The title to be displayed for each item of this activity



20
21
22
# File 'lib/refinery/activity.rb', line 20

def title
  @title
end

#updated_imageObject

Image asset to use to represent updated instance of the class thisa activity represents



23
24
25
# File 'lib/refinery/activity.rb', line 23

def updated_image
  @updated_image
end

#urlObject



109
110
111
# File 'lib/refinery/activity.rb', line 109

def url
  @url ||= "refinery.#{url_prefix}#{Refinery.route_for_model(klass)}"
end

#url_prefixObject



103
104
105
# File 'lib/refinery/activity.rb', line 103

def url_prefix
  "#{"#{@url_prefix}_".gsub("__", "_") if @url_prefix.present?}"
end

#use_record_in_nestingObject

Boolean; whether or not to use the record itself when constructing the nesting Default true



27
28
29
# File 'lib/refinery/activity.rb', line 27

def use_record_in_nesting
  @use_record_in_nesting
end

Instance Method Details

#base_class_nameObject

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"


77
78
79
# File 'lib/refinery/activity.rb', line 77

def base_class_name
  self.klass.name.demodulize
end

#klassObject

Returns the Class Constant for the Class which this instance is recording

Example:

activity.klass => Refinery::Image


85
86
87
# File 'lib/refinery/activity.rb', line 85

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 routes.



91
92
93
94
95
96
97
98
99
# File 'lib/refinery/activity.rb', line 91

def nesting(record_string = "record")
  @nesting ||= begin
    chain = self.nested_with.inject([]) { |nest_chain, nesting|
      nest_chain << "#{record_string}.#{nesting}"
    }
    chain << record_string if self.use_record_in_nesting
    chain.join(',')
  end
end