Class: CSVStepImporter::Row
- Defined in:
- lib/csv_step_importer/row.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#row_number ⇒ Object
Returns the value of attribute row_number.
Attributes inherited from Node
Instance Method Summary collapse
- #create_or_update ⇒ Object
-
#dao_for(model, pluralize: false) ⇒ Object
retrieve a dao for a different model using the same CSV row.
- #headers ⇒ Object
- #include_row? ⇒ Boolean
-
#initialize(parent:, row_number:, **attributes) ⇒ Row
constructor
Logic.
- #method_missing(sym) ⇒ Object
Methods inherited from Node
#add_children, #build_env, #run_validations!, #validate_children
Methods inherited from Base
#ancestors, #assign_attributes, #inspect, #persisted?, #save, #save!, set, #to_s, #update
Constructor Details
#initialize(parent:, row_number:, **attributes) ⇒ Row
Logic
17 18 19 20 21 22 23 |
# File 'lib/csv_step_importer/row.rb', line 17 def initialize(parent:, row_number:, **attributes) super parent: parent self.cache = {} self.attributes = attributes self.row_number = row_number end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym) ⇒ Object
43 44 45 |
# File 'lib/csv_step_importer/row.rb', line 43 def method_missing(sym, *) attributes.fetch(sym) { attributes.fetch(sym.to_s) { headers&.include?(sym) ? nil : super } } end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/csv_step_importer/row.rb', line 5 def attributes @attributes end |
#cache ⇒ Object
Returns the value of attribute cache.
5 6 7 |
# File 'lib/csv_step_importer/row.rb', line 5 def cache @cache end |
#row_number ⇒ Object
Returns the value of attribute row_number.
5 6 7 |
# File 'lib/csv_step_importer/row.rb', line 5 def row_number @row_number end |
Instance Method Details
#create_or_update ⇒ Object
25 26 27 28 |
# File 'lib/csv_step_importer/row.rb', line 25 def create_or_update # Rowの保存処理は基本的にstepsで行います true end |
#dao_for(model, pluralize: false) ⇒ Object
retrieve a dao for a different model using the same CSV row. This is useful e.g. if you use the reflector to get ids of related data
31 32 33 |
# File 'lib/csv_step_importer/row.rb', line 31 def dao_for(model, pluralize: false) cache[model.cache_key(pluralize: pluralize)] end |
#headers ⇒ Object
39 40 41 |
# File 'lib/csv_step_importer/row.rb', line 39 def headers ancestors.find { |ancestor|ancestor.respond_to?(:headers) }&.headers end |
#include_row? ⇒ Boolean
35 36 37 |
# File 'lib/csv_step_importer/row.rb', line 35 def include_row? ignore_invalid_rows ? valid? : true end |