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
# 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.commands = []
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 (readonly)

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.



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

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