Class: ActiveRecord::Bixformer::Model::Csv::Base
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Bixformer::Model::Csv::Base
show all
- Defined in:
- lib/activerecord-bixformer/model/csv/base.rb
Instance Attribute Summary
Attributes inherited from Base
#associations, #attributes, #errors, #name, #options, #parent, #preferred_skip_attributes, #translator
Instance Method Summary
collapse
Methods inherited from Base
#activerecord_constant, #add_association, #find_record_by!, #initialize, #parent_foreign_key, #parents, #plan, #set_parent, #setup, #should_be_included
#presence_value?
Instance Method Details
#csv_title(attribute_name) ⇒ Object
Also known as:
translate
40
41
42
|
# File 'lib/activerecord-bixformer/model/csv/base.rb', line 40
def csv_title(attribute_name)
@translator.translate_attribute(attribute_name)
end
|
#csv_titles ⇒ Object
36
37
38
|
# File 'lib/activerecord-bixformer/model/csv/base.rb', line 36
def csv_titles
sort(sortable_csv_titles)
end
|
#export(record_or_relation) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/activerecord-bixformer/model/csv/base.rb', line 6
def export(record_or_relation)
errors.clear
run_bixformer_callback :export do
do_export(record_or_relation)
end
end
|
#import(csv_body_row, parent_record_id = nil) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/activerecord-bixformer/model/csv/base.rb', line 14
def import(csv_body_row, parent_record_id = nil)
errors.clear
run_bixformer_callback :import do
do_import(csv_body_row, parent_record_id)
end
end
|
#verify_csv_titles(csv_title_row) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/activerecord-bixformer/model/csv/base.rb', line 22
def verify_csv_titles(csv_title_row)
verified_attribute_names = if options[:verified_csv_titles]
options[:verified_csv_titles].map(&:to_s)
else
activerecord_constant.attribute_names
end
@attributes
.select { |attr| verified_attribute_names.include?(attr.name) }
.map { |attr| csv_title(attr.name) }
.all? { |title| csv_title_row.include?(title) } &&
@associations.all? { |ass| ass.verify_csv_titles(csv_title_row) }
end
|