Class: DatabaseClonerRails::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/database_cloner_rails/uploader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(only: nil) ⇒ Uploader

Returns a new instance of Uploader.



7
8
9
# File 'lib/database_cloner_rails/uploader.rb', line 7

def initialize(only: nil)
  @only = Array(only).map(&:to_s).reject(&:empty?)
end

Class Method Details

.run(only: nil) ⇒ Object



3
4
5
# File 'lib/database_cloner_rails/uploader.rb', line 3

def self.run(only: nil)
  new(only: only).run
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/database_cloner_rails/uploader.rb', line 11

def run
  tables = ActiveRecord::Base.connection.tables
  tables = tables.select { |t| @only.include?(t) } if @only.any?
  tables.each do |table|
    next unless table.classify.safe_constantize.present?
    begin
      require "tasks/database_cloner/db_dump/#{table}"
    rescue LoadError, StandardError => e
      puts "Oops!! #{table} could not be uploaded."
    end
  end
end