Class: Importer::Import::Simple

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

Overview

Simple import summary. It’s not stored in database (as with ActiveRecord import).

Attributes:

  • new_objects_count - number of new objects created during the import

  • existing_objects_count - number of objects modified during the import

  • invalid_objects_count - number of objects that couldn’t have been imported

  • workflow_state - import may be in one of three states: ready, started or finished. The state changes during the import process.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimple

Returns a new instance of Simple.



22
23
24
25
26
27
28
# File 'lib/importer/import/simple.rb', line 22

def initialize
  @state                  = "ready"
  @new_objects_count      = 0
  @existing_objects_count = 0
  @invalid_objects_count  = 0
  @imported_objects       = []
end

Instance Attribute Details

#existing_objects_countObject (readonly)

Returns the value of attribute existing_objects_count.



12
13
14
# File 'lib/importer/import/simple.rb', line 12

def existing_objects_count
  @existing_objects_count
end

#imported_objectsObject (readonly)

Returns the value of attribute imported_objects.



12
13
14
# File 'lib/importer/import/simple.rb', line 12

def imported_objects
  @imported_objects
end

#invalid_objects_countObject (readonly)

Returns the value of attribute invalid_objects_count.



12
13
14
# File 'lib/importer/import/simple.rb', line 12

def invalid_objects_count
  @invalid_objects_count
end

#new_objects_countObject (readonly)

Returns the value of attribute new_objects_count.



12
13
14
# File 'lib/importer/import/simple.rb', line 12

def new_objects_count
  @new_objects_count
end

#stateObject (readonly)

Returns the value of attribute state.



12
13
14
# File 'lib/importer/import/simple.rb', line 12

def state
  @state
end

Class Method Details

.createObject



15
16
17
18
19
# File 'lib/importer/import/simple.rb', line 15

def create
  import = new
  import.save
  import
end

Instance Method Details

#add_object(imported_object) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/importer/import/simple.rb', line 38

def add_object(imported_object)
  case imported_object.state
  when "new_object"
    @new_objects_count += 1
  when "existing_object"
    @existing_objects_count += 1
  when "invalid_object"
    @invalid_objects_count += 1
  end
  @imported_objects << imported_object
end

#build_imported_objectObject



56
57
58
# File 'lib/importer/import/simple.rb', line 56

def build_imported_object
  Importer::ImportedObject::Simple.new(:import => self)
end

#finish!Object



34
35
36
# File 'lib/importer/import/simple.rb', line 34

def finish!
  @state = "finished"
end

#saveObject Also known as: save!



50
51
52
# File 'lib/importer/import/simple.rb', line 50

def save
  true
end

#start!Object



30
31
32
# File 'lib/importer/import/simple.rb', line 30

def start!
  @state = "started"
end