Class: ModelExplorer::Import

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

Constant Summary collapse

FAKE_PASSWORD =
"FakePa$$word12345!"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_data) ⇒ Import

Returns a new instance of Import.

Parameters:

  • record_data (String)

    JSON representation of the record



10
11
12
13
14
# File 'lib/model_explorer/import.rb', line 10

def initialize(record_data)
  @record_data = record_data
  @record = nil
  @model = nil
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/model_explorer/import.rb', line 7

def model
  @model
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/model_explorer/import.rb', line 6

def record
  @record
end

#record_dataObject (readonly)

Returns the value of attribute record_data.



5
6
7
# File 'lib/model_explorer/import.rb', line 5

def record_data
  @record_data
end

Instance Method Details

#importActiveRecord::Base

Returns:

  • (ActiveRecord::Base)


17
18
19
20
21
22
23
24
# File 'lib/model_explorer/import.rb', line 17

def import
  @model = record_data[:model].constantize
  @record = model.find_or_initialize_by(record_data[:attributes])

  create_record_with_associations!

  record
end