Class: Rexport::RexportModel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, path = nil) ⇒ RexportModel

Returns a new instance of RexportModel.



5
6
7
8
# File 'lib/rexport/rexport_model.rb', line 5

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.



3
4
5
# File 'lib/rexport/rexport_model.rb', line 3

def klass
  @klass
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/rexport/rexport_model.rb', line 3

def path
  @path
end

Instance Method Details

#collection_from_association(association) ⇒ Object



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

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



14
15
16
# File 'lib/rexport/rexport_model.rb', line 14

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

#filter_column(field) ⇒ Object



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

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



29
30
31
# File 'lib/rexport/rexport_model.rb', line 29

def name
  klass.name
end

#rexport_fields_arrayObject



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

def rexport_fields_array
  klass.rexport_fields_array
end