Class: Refinery::Activity

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Activity) initialize(options = {})

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 'core/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

- (Object) class_name

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



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

def class_name
  @class_name
end

- (Object) conditions

Returns the value of attribute conditions



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

def conditions
  @conditions
end

- (Object) created_image

Image asset to use to represent newly created instances of the class this activity represents



7
8
9
# File 'core/lib/refinery/activity.rb', line 7

def created_image
  @created_image
end

- (Object) limit

Total number of activies to show for a given class of activity



10
11
12
# File 'core/lib/refinery/activity.rb', line 10

def limit
  @limit
end

- (Object) nested_with

Returns the value of attribute nested_with



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

def nested_with
  @nested_with
end

- (Object) order

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



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

def order
  @order
end

- (Object) title

The title to be displayed for each item of this activity



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

def title
  @title
end

- (Object) updated_image

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



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

def updated_image
  @updated_image
end

- (Object) url



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

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

- (Object) url_prefix



92
93
94
# File 'core/lib/refinery/activity.rb', line 92

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

Instance Method Details

- (Object) base_class_name

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 'core/lib/refinery/activity.rb', line 70

def base_class_name
  self.klass.name.demodulize
end

- (Object) klass

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

Example:

activity.klass => Refinery::Image


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

def klass
  self.class_name.constantize
end

- (Object) nesting(record_string = "record")

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 'core/lib/refinery/activity.rb', line 84

def nesting(record_string = "record")
  self.nested_with.inject("") { |nest_chain, nesting|
    nest_chain << "#{record_string}.#{nesting},"
  }
end