Class: ArtVandelay::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/art_vandelay.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(model_name, **options) ⇒ Import

Returns a new instance of Import.



142
143
144
145
146
147
# File 'lib/art_vandelay.rb', line 142

def initialize(model_name, **options)
  @options = options.symbolize_keys
  @rollback = options[:rollback]
  @strip = options[:strip]
  @model_name = model_name
end

Instance Method Details

#csv(csv_string, **options) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/art_vandelay.rb', line 149

def csv(csv_string, **options)
  options = options.symbolize_keys
  headers = options[:headers] || true
  attributes = options[:attributes] || {}
  rows = build_csv(csv_string, headers)

  if rollback
    # TODO: It would be nice to still return a result object during a
    # failure
    active_record.transaction do
      parse_rows(rows, attributes, raise_on_error: true)
    end
  else
    parse_rows(rows, attributes)
  end
end