class Integral::ActsAsListable::ActiveRecord::Base

ActiveRecord::Base extension

Public Class Methods

acts_as_listable(_options = {}) click to toggle source

Adds listable behaviour to objects

# File lib/integral/acts_as_listable.rb, line 18
def self.acts_as_listable(_options = {})
  Integral::ActsAsListable.objects << self unless Integral::ActsAsListable.objects.map(&:name).include?(self.name)

  # @return [Hash] instance as a list item
  # Keys include: id, title, subtitle, image, description, url
  def to_list_item
    raise NotImplementedError
  end

  # @return [Hash] listable options to be used within a RecordSelector widget.
  # Expects the following keys: record_title, selector_path, selector_title
  # TODO: Move these options into acts_as_listable initializer
  def self.listable_options
    raise NotImplementedError
  end

  before_save :touch_list_items

  # Touch all list items the instance is associated with
  def touch_list_items
    list_items = Integral::ListItem.where(type: 'Integral::Object', object_id: id, object_type: self.class.to_s)
    list_items.find_each(&:touch)
  end
end
listable_options() click to toggle source

@return [Hash] listable options to be used within a RecordSelector widget. Expects the following keys: record_title, selector_path, selector_title TODO: Move these options into acts_as_listable initializer

# File lib/integral/acts_as_listable.rb, line 30
def self.listable_options
  raise NotImplementedError
end

Public Instance Methods

to_list_item() click to toggle source

@return [Hash] instance as a list item Keys include: id, title, subtitle, image, description, url

# File lib/integral/acts_as_listable.rb, line 23
def to_list_item
  raise NotImplementedError
end
touch_list_items() click to toggle source

Touch all list items the instance is associated with

# File lib/integral/acts_as_listable.rb, line 37
def touch_list_items
  list_items = Integral::ListItem.where(type: 'Integral::Object', object_id: id, object_type: self.class.to_s)
  list_items.find_each(&:touch)
end