Class: RailsExporter::Base
- Inherits:
-
Object
- Object
- RailsExporter::Base
- Includes:
- Exporter
- Defined in:
- lib/rails_exporter/base.rb
Class Method Summary collapse
- .column(attr, &block) ⇒ Object
- .columns(exporter_name = :default) ⇒ Object
-
.exporter(context = :default, &block) ⇒ Object
def method_missing(m, *args, &block) if m =~ /_url|_path/ Rails.application.routes.url_helpers.send(m, args) end end.
- .file_types ⇒ Object
Methods included from Exporter
Class Method Details
.column(attr, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rails_exporter/base.rb', line 27 def column(attr, &block) if attr.is_a?(Hash) attribute = attr.keys.first.to_s.to_sym type = attr.values.first.to_s.to_sym else attribute = attr.to_sym type = :string end exporter_name_without_suffix = self.to_s.underscore.gsub('_exporter','') label = I18n.t("#{@exporter_context}.#{attribute}", default: [attribute.to_sym, attribute.to_s.humanize], scope: [:exporters, exporter_name_without_suffix]) self.exporters[@exporter_context] << {column: attribute, label: label, type: normalize_type(type), block: (block_given? ? block : nil)} end |
.columns(exporter_name = :default) ⇒ Object
41 42 43 |
# File 'lib/rails_exporter/base.rb', line 41 def columns(exporter_name=:default) self.exporters[exporter_name] end |
.exporter(context = :default, &block) ⇒ Object
def method_missing(m, *args, &block)
if m =~ /_url|_path/
Rails.application.routes.url_helpers.send(m, args)
end
end
20 21 22 23 24 25 |
# File 'lib/rails_exporter/base.rb', line 20 def exporter(context=:default, &block) (self.exporters ||= {})[context] ||= [] @exporter_context = context block.call if block_given? self.exporters[context] end |
.file_types ⇒ Object
10 11 12 |
# File 'lib/rails_exporter/base.rb', line 10 def file_types [:csv, :xls, :xlsx, :xml] end |