Class: Rexport::RexportModel

Inherits:
Object
  • Object
show all
Defined in:
lib/rexport/export_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, path = nil) ⇒ RexportModel

Returns a new instance of RexportModel.



10
11
12
13
# File 'lib/rexport/export_methods.rb', line 10

def initialize(klass, path = nil)
  self.klass = klass
  self.path = path.to_s unless path.blank?
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



8
9
10
# File 'lib/rexport/export_methods.rb', line 8

def klass
  @klass
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/rexport/export_methods.rb', line 8

def path
  @path
end

Instance Method Details

#collection_from_association(association) ⇒ Object



23
24
25
26
# File 'lib/rexport/export_methods.rb', line 23

def collection_from_association(association)
  return klass.send("find_#{association}_for_rexport") if klass.respond_to?("find_#{association}_for_rexport")
  klass.reflect_on_association(association.to_sym).klass.all
end

#field_path(field_name) ⇒ Object



19
20
21
# File 'lib/rexport/export_methods.rb', line 19

def field_path(field_name)
  [path, field_name].compact * '.'
end

#filter_column(field) ⇒ Object



28
29
30
31
32
# File 'lib/rexport/export_methods.rb', line 28

def filter_column(field)
  return field.method unless field.method.include?('.')
  association = field.method.split('.').first
  klass.reflect_on_association(association.to_sym).foreign_key
end

#nameObject



34
35
36
# File 'lib/rexport/export_methods.rb', line 34

def name
  klass.name
end

#rexport_fields_arrayObject



15
16
17
# File 'lib/rexport/export_methods.rb', line 15

def rexport_fields_array
  klass.rexport_fields_array
end