Sha256: 1466fd24708e21ede87add912dab53081af06128c0a32b1f88ca75571c882b42

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module Import
  class NoRelation < Resource
    protected
    
    def parse_resource(resource)
      resource.gsub('*', '').strip
    end
    
    def append_existing_resources_criteria(resource)
      @existing_resources_criteria << "(#{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.2 lib/import/no_relation.rb