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]


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/refinery/activity.rb', line 35

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"
  }.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



51
52
53
# File 'lib/refinery/activity.rb', line 51

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

Returns the value of attribute nested_with.



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

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



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

def order
  @order
end

#titleObject

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_imageObject

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

#urlObject



98
99
100
# File 'lib/refinery/activity.rb', line 98

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

#url_prefixObject



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_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"


70
71
72
# File 'lib/refinery/activity.rb', line 70

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


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