Module: CsvRowModel::Import::Represents

Extended by:
ActiveSupport::Concern
Includes:
CheckOptions
Included in:
CsvRowModel::Import
Defined in:
lib/csv_row_model/concerns/import/represents.rb

Instance Method Summary collapse

Instance Method Details

#all_attributesObject


28
29
30
# File 'lib/csv_row_model/concerns/import/represents.rb', line 28

def all_attributes
  attributes.merge!(representations)
end

#filter_errorsObject (protected)

remove each dependent attribute from errors if it's representation dependencies are in the errors


41
42
43
44
45
46
# File 'lib/csv_row_model/concerns/import/represents.rb', line 41

def filter_errors
  self.class.representation_names.each do |representation_name|
    next unless errors.messages.slice(*representation_objects[representation_name].dependencies).present?
    errors.delete representation_name
  end
end

#representation_objectsObject


14
15
16
17
18
# File 'lib/csv_row_model/concerns/import/represents.rb', line 14

def representation_objects
  @representation_objects ||= array_to_block_hash(self.class.representation_names) do |representation_name|
    Representation.new(representation_name, self.class.representations[representation_name], self)
  end
end

#representation_value(representation_name) ⇒ Object


20
21
22
# File 'lib/csv_row_model/concerns/import/represents.rb', line 20

def representation_value(representation_name)
  representation_objects[representation_name].try(:value)
end

#representationsObject


24
25
26
# File 'lib/csv_row_model/concerns/import/represents.rb', line 24

def representations
  attributes_from_method_names(self.class.representation_names)
end

#valid?(*args) ⇒ Boolean

Returns:


32
33
34
35
36
# File 'lib/csv_row_model/concerns/import/represents.rb', line 32

def valid?(*args)
  super
  filter_errors
  errors.empty?
end