Class: Bukovina::Importers::MemoryName

Inherits:
Object
  • Object
show all
Defined in:
lib/bukovina/importers/memory_name.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs, o_attrs = {}) ⇒ MemoryName

Returns a new instance of MemoryName.



3
4
5
# File 'lib/bukovina/importers/memory_name.rb', line 3

def initialize attrs, o_attrs = {}
@o_attrs = o_attrs
@attrs = [ attrs.deep_dup ].flatten ; end

Instance Method Details

#importObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bukovina/importers/memory_name.rb', line 7

def import
      @attrs.each do |attrs|
# find name
name_attrs = attrs.delete( :name )
name_attrs.delete( :bond_to )
attrs[ :name ] = 
begin
   Name.where( name_attrs ).first || raise
rescue RuntimeError
   Bukovina::Importers::Name.new( name_attrs ).import
   retry ; end

mn_attrs = attrs.merge( @o_attrs )
MemoryName.where( mn_attrs ).first_or_initialize.save!
end ; end