Class: Bukovina::Importers::Memo
- Inherits:
-
Object
- Object
- Bukovina::Importers::Memo
- Includes:
- FindInit
- Defined in:
- lib/bukovina/importers/memo.rb
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(attrs, o_attrs = {}) ⇒ Memo
constructor
A new instance of Memo.
Methods included from FindInit
#foreign_class, #parse_array, #parse_hash, #separate_hash
Constructor Details
#initialize(attrs, o_attrs = {}) ⇒ Memo
Returns a new instance of Memo.
64 65 |
# File 'lib/bukovina/importers/memo.rb', line 64 def initialize attrs, o_attrs = {} @attrs = [ attrs.deep_dup ].flatten ;end |
Instance Method Details
#import ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bukovina/importers/memo.rb', line 4 def import @attrs.each do |attrs| # find name bond_to_marker = attrs.delete( :bond_to_marker ) (search_attrs, new_attrs) = separate_hash( parse_hash( ::Memo, attrs ) ) calendary_attrs = new_attrs.delete( :calendary_attributes ) calendary_attrs[ :slugs ] = calendary_attrs.delete( :slugs_attributes ) new_attrs[ :calendary ] = calendary_attrs.is_a?( Calendary ) && calendary_attrs || Calendary.includes( :slug ).where( calendary_attrs ).first event_attrs = new_attrs.delete( :event_attributes ) new_attrs[ :event ] = event_attrs.is_a?( Event ) && event_attrs || ( memory_attrs = event_attrs.delete( :memory_attributes ) event_attrs[ :memory ] = Memory.where( memory_attrs ).first Event.where( event_attrs ).first) if !new_attrs[ :calendary ] || !new_attrs[ :event ] Kernel.puts "EVENT ORIG: #{attrs.inspect}" Kernel.puts "EVENT: #{new_attrs.inspect}" r = true binding.pry raise SecurityError if r ;end search_attrs[ :calendary_id ] = new_attrs[ :calendary ].id search_attrs[ :event_id ] = new_attrs[ :event ].id if bond_to_marker base_search_attrs = search_attrs.merge( year_date: bond_to_marker, bind_kind: 'несвязаный' ) memo = Memo.where( base_search_attrs ).first if !memo r = true binding.pry raise SecurityError if r ;end new_attrs[ :bond_to_id ] = memo.id ;end binding.pry if ENV['DEBUG'] memo = Memo.new( new_attrs ) memo.valid? search_attrs[ :year_date ] = memo.year_date #Kernel.puts "EVENT ATTRS: #{search_attrs.inspect}" Memo.where( search_attrs ).first || ( memo.services = memo.services.map do |service| old = Service.where(name: service.name, alphabeth_code: service.alphabeth_code).first old || service ;end begin memo.save! rescue r = true binding.pry raise SecurityError if r ;end ) #;end #rescue # binding.pry end;end |