Sha256: 047608d9e81b0248247802019272c468f07bf42ac64c46b6d1db74ca3c913c59

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Import
  class NoRelation < Resource    
    attr_accessible :logger, :input, :email, :resource_class
    attr_accessor :resource_class 
    
    protected
    
    def parse_resource(resource)
      resource.gsub('*', '').strip
    end
    
    def append_existing_resources_criteria(resource)
      @existing_resources_criteria << "(#{resource_class.table_name}.name = ?)"
      @existing_resources_criteria_values << resource
    end
    
    def import_resources   
      log "#{parsed_resources_missing.length} of #{@parsed_resources.length} new #{resource_class.name.humanize.pluralize}."  
      
      new_resources_data = []
      
      parsed_resources_missing.each do |resource|            
        new_resources_data << new_record(resource)
      end
      
      log "Creating #{new_resources_data.length} new #{resource_class.name.humanize.pluralize}."
      
      unless new_resources_data.empty?
        resource_class.import(columns, new_resources_data, :validate => false)
      end 
    end
    
    def parsed_resources_missing
      @parsed_resources_missing ||= @parsed_resources.select{|r| !collection(false).map(&:second).include?(r) }  
    end
    
    def new_record(resource)
      [resource]
    end
    
    def columns
      [:name]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
import-0.0.3 lib/import/no_relation.rb