Module: CsvRowModel::Import::ParsedModel

Extended by:
ActiveSupport::Concern
Included in:
Attributes
Defined in:
lib/csv_row_model/concerns/import/parsed_model.rb

Defined Under Namespace

Classes: Model

Instance Method Summary collapse

Instance Method Details

#_original_attribute(column_name) ⇒ Object (protected)


26
27
28
29
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 26

def _original_attribute(column_name)
  parsed_model.valid?
  return nil unless parsed_model.errors[column_name].blank?
end

#parsed_modelImport::ParsedModel::Model

Returns a model with validations related to parsed_model (values are from format_cell)

Returns:


17
18
19
20
21
22
23
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 17

def parsed_model
  @parsed_model ||= begin
    attribute_objects = _attribute_objects
    formatted_hash = array_to_block_hash(self.class.column_names) { |column_name| attribute_objects[column_name].formatted_value }
    self.class.parsed_model_class.new(formatted_hash)
  end
end

#valid?(*args) ⇒ Boolean

Returns:


6
7
8
9
10
11
12
13
14
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 6

def valid?(*args)
  super
  call_wrapper = using_warnings? ? parsed_model.method(:using_warnings) : ->(&block) { block.call }
  call_wrapper.call do
    parsed_model.valid?(*args)
    errors.messages.merge!(parsed_model.errors.messages.reject {|k, v| v.empty? })
    errors.empty?
  end
end