Module: Axlsx::Ar::ClassMethods

Defined in:
lib/acts_as_xlsx/ar.rb

Overview

Class methods for the mixin

Instance Method Summary collapse

Instance Method Details

#acts_as_xlsx(options = {}) ⇒ Object

defines the class method to inject to_xlsx

Examples:

class MyModel < ActiveRecord::Base
   acts_as_xlsx :columns=> [:id, :created_at, :updated_at], :i18n => 'activerecord.attributes'

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • columns (Array, Symbol)

    an array of symbols defining the columns and methods to call in generating sheet data for each row.

  • i18n (String) — default: default nil

    The path to search for localization. When this is specified your i18n.t will be used to determine the labels for columns.



28
29
30
31
32
33
# File 'lib/acts_as_xlsx/ar.rb', line 28

def acts_as_xlsx(options={})
  cattr_accessor :xlsx_i18n, :xlsx_columns
  self.xlsx_i18n = options.delete(:i18n) || false
  self.xlsx_columns = options.delete(:columns) ||  self.column_names.map { |c| c = c.to_sym }
  extend Axlsx::Ar::SingletonMethods
end