Class: Para::Exporter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/para/exporter/base.rb

Direct Known Subclasses

Csv

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/para/exporter/base.rb', line 7

def initialize(resources)
  @resources = resources
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



4
5
6
# File 'lib/para/exporter/base.rb', line 4

def resources
  @resources
end

Class Method Details

.exports(model_name) ⇒ Object



19
20
21
# File 'lib/para/exporter/base.rb', line 19

def self.exports model_name
  self.model_name = model_name
end

.register_base_exporter(type, exporter) ⇒ Object



35
36
37
# File 'lib/para/exporter/base.rb', line 35

def self.register_base_exporter(type, exporter)
  Exporter.base_exporters[type] = exporter
end

Instance Method Details

#dispositionObject



23
24
25
# File 'lib/para/exporter/base.rb', line 23

def disposition
  'inline'
end

#extensionObject



27
28
29
# File 'lib/para/exporter/base.rb', line 27

def extension
  raise '#extension must be defined to create the export file name'
end

#file_nameObject



31
32
33
# File 'lib/para/exporter/base.rb', line 31

def file_name
  @file_name ||= [name, extension].join('.')
end

#modelObject



11
12
13
14
15
16
17
# File 'lib/para/exporter/base.rb', line 11

def model
  @model ||= if (model_name = self.class.model_name)
    model_name.constantize
  else
    raise 'You must define model to export in your exporter as following: `exports \'YourModelName\'`'
  end
end