7 def self.included(base)
8 base.extend(ClassMethods)
9 base.__send__ :include, InstanceMethods
19 def modify_object(name, attr, key = 'name')
20 c = 'find_by_' + key.to_s
21 r = self.__send__ c, name
26 r[key] = name if r[key].blank?
31 def import_text(data, &blk)
32 d = JSON.parse_no_except(data)
36 d.each do |name, item|
37 m = blk.call(name, item)
38 res.push(m) unless m.valid?
40 raise ActiveRecord::Rollback unless res.empty?
45 def import_file(filename, &blk)
48 t = File.open(filename, 'r').read
52 self.import_text t, &blk
57 module InstanceMethods
65 include PettanImporter