Class: RedisImporter::RedisImporter

Inherits:
Object
  • Object
show all
Includes:
GemConfigurator
Defined in:
lib/redis_importer/redis_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRedisImporter

Instantiates and configures a RedisImporter object



9
10
11
12
13
14
15
16
17
# File 'lib/redis_importer/redis_importer.rb', line 9

def initialize
  configure
  self.collection = Object::const_get("#{@settings['storage_method'].camelcase}Collection").new()
  
  self.files = self.collection.files
  self.errors = []
  self.commands = []
  self.run_pipeline = true
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



6
7
8
# File 'lib/redis_importer/redis_importer.rb', line 6

def collection
  @collection
end

#commandsObject

Returns the value of attribute commands.



5
6
7
# File 'lib/redis_importer/redis_importer.rb', line 5

def commands
  @commands
end

#errorsObject

Returns the value of attribute errors.



5
6
7
# File 'lib/redis_importer/redis_importer.rb', line 5

def errors
  @errors
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/redis_importer/redis_importer.rb', line 5

def files
  @files
end

Instance Method Details

#importObject

Converts each csv file in the collection to objects, which are then saved into the redis store.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/redis_importer/redis_importer.rb', line 20

def import
  files.each do |file|
    save_remote_file_locally(file)
    begin
      convert_to_redis_commands(file) if class_exists?(file.to_class_name.to_sym)
    rescue NameError
      add_errors("#{file.name} is not matched by a class #{file.to_class_name} in the system.")
      add_errors($!)
    end
  end

  pipeline
end