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

Overview

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

Methods

Public Instance methods

Creates a Ruport::Data::Table from an ActiveRecord find. Takes parameters just like a regular find.

Additional options include:

:only:An attribute name or array of attribute names to include in the results, other attributes will be excuded.
:except:An attribute name or array of attribute names to exclude from the results.
:methods:A method name or array of method names whose result(s) will be included in the table.
:include:An associated model or array of associated models to include in the results.
:filters:A proc or array of procs that set up conditions to filter the data being added to the table.
:transforms:A proc or array of procs that perform transformations on the data being added to the table.
:record_class:Specify the class of the table‘s records.
:eager_loading:Set to false if you don‘t want to eager load included associations.

The :only, :except, :methods, and :include options may also be passed to the :include option in order to specify the output for any associated models. In this case, the :include option must be a hash, where the keys are the names of the associations and the values are hashes of options.

Any options passed to report_table will disable the options set by the acts_as_reportable class method.

Example:

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

  Book.report_table(:all, :only => ['title'],
    :include => { :author => { :only => 'name' } }).as(:html)

Returns:

an html version of the table with two columns, title from the book, and name from the associated author.

Example:

  Book.report_table(:all, :include => :author).as(:html)

Returns:

an html version of the table with all columns from books and authors.

Note: column names for attributes of included models will be qualified with the name of the association.

Creates a Ruport::Data::Table from an ActiveRecord find_by_sql.

Additional options include:

:filters:A proc or array of procs that set up conditions to filter the data being added to the table.
:transforms:A proc or array of procs that perform transformations on the data being added to the table.
:record_class:Specify the class of the table‘s records.

Example:

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

  Book.report_table_by_sql("SELECT * FROM books")

[Validate]