Module Ruport::Reportable::InstanceMethods
In: lib/ruport/acts_as_reportable.rb

Overview

This module contains methods that will be made available as instance methods to any ActiveRecord model that calls acts_as_reportable.

Methods

Public Instance methods

Grabs all of the object‘s attributes and the attributes of the associated objects and returns them as an array of record hashes.

Associated object attributes are stored in the record with "association.attribute" keys.

Passing :only as an option will only get those attributes. Passing :except as an option will exclude those attributes. Must pass :include as an option to access associations. Options may be passed to the included associations by providing the :include option as a hash. Passing :methods as an option will include any methods on the object.

Example:

  class Book < ActiveRecord::Base
    belongs_to :author
    acts_as_reportable
  end

  abook.reportable_data(:only => ['title'], :include => [:author])

Returns:

  [{'title' => 'book title',
    'author.id' => 'author id',
    'author.name' => 'author name' }]

NOTE: title will only be returned if the value exists in the table. If the books table does not have a title column, it will not be returned.

Example:

  abook.reportable_data(:only => ['title'],
    :include => { :author => { :only => ['name'] } })

Returns:

  [{'title' => 'book title',
    'author.name' => 'author name' }]

[Validate]