Class: Rexport::RexportModel
- Inherits:
-
Object
- Object
- Rexport::RexportModel
- Defined in:
- lib/rexport/rexport_model.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #collection_from_association(association) ⇒ Object
- #field_path(field_name) ⇒ Object
- #filter_column(field) ⇒ Object
-
#initialize(klass, path = nil) ⇒ RexportModel
constructor
A new instance of RexportModel.
- #name ⇒ Object
- #rexport_fields_array ⇒ Object
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
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/rexport/rexport_model.rb', line 3 def klass @klass end |
#path ⇒ Object
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 |
#name ⇒ Object
29 30 31 |
# File 'lib/rexport/rexport_model.rb', line 29 def name klass.name end |
#rexport_fields_array ⇒ Object
10 11 12 |
# File 'lib/rexport/rexport_model.rb', line 10 def rexport_fields_array klass.rexport_fields_array end |