Object
# File lib/taps/operation.rb, line 189 def self.factory(type, database_url, remote_url, opts) type = :resume if opts[:resume] klass = case type when :pull then Taps::Pull when :push then Taps::Push when :resume then eval(opts[:klass]) else raise "Unknown Operation Type -> #{type}" end klass.new(database_url, remote_url, opts) end
# File lib/taps/operation.rb, line 39 def apply_table_filter(tables) return tables unless table_filter re = Regexp.new(table_filter) if tables.kind_of?(Hash) ntables = {} tables.each do |t, d| unless re.match(t.to_s).nil? ntables[t] = d end end ntables else tables.reject { |t| re.match(t.to_s).nil? } end end
# File lib/taps/operation.rb, line 139 def close_session @session_resource.delete(http_headers) if @session_resource end
# File lib/taps/operation.rb, line 103 def completed_tables opts[:completed_tables] ||= [] end
# File lib/taps/operation.rb, line 115 def compression_disabled? !!opts[:disable_compression] end
# File lib/taps/operation.rb, line 119 def db @db ||= Sequel.connect(database_url) end
# File lib/taps/operation.rb, line 99 def default_chunksize opts[:default_chunksize] end
# File lib/taps/operation.rb, line 165 def format_number(num) num.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,") end
# File lib/taps/operation.rb, line 155 def http_headers(extra = {}) base = { :taps_version => Taps.compatible_version } if compression_disabled? base[:accept_encoding] = "" else base[:accept_encoding] = "gzip, deflate" end base.merge(extra) end
# File lib/taps/operation.rb, line 31 def indexes_first? !!opts[:indexes_first] end
# File lib/taps/operation.rb, line 95 def resuming? opts[:resume] == true end
# File lib/taps/operation.rb, line 151 def safe_database_url safe_url(database_url) end
# File lib/taps/operation.rb, line 147 def safe_remote_url safe_url(remote_url) end
# File lib/taps/operation.rb, line 143 def safe_url(url) url.sub(/\/\/(.+?)?:(.*?)@/, '//\1:[hidden]@') end
# File lib/taps/operation.rb, line 123 def server @server ||= RestClient::Resource.new(remote_url) end
# File lib/taps/operation.rb, line 127 def session_resource @session_resource ||= begin @session_uri ||= server['sessions'].post('', http_headers).to_s server[@session_uri] end end
# File lib/taps/operation.rb, line 134 def set_session(uri) session_uri = uri @session_resource = server[session_uri] end
# File lib/taps/operation.rb, line 83 def setup_signal_trap trap("INT") { puts "\nCompleting current action..." @exiting = true } trap("TERM") { puts "\nCompleting current action..." @exiting = true } end
# File lib/taps/operation.rb, line 59 def store_session file = "#{file_prefix}_#{Time.now.strftime("%Y%m%d%H%M")}.dat" puts "\nSaving session to #{file}.." File.open(file, 'w') do |f| f.write(to_hash.to_json) end end
# File lib/taps/operation.rb, line 107 def stream_state opts[:stream_state] ||= {} end
# File lib/taps/operation.rb, line 111 def stream_state=(val) opts[:stream_state] = val end
# File lib/taps/operation.rb, line 35 def table_filter opts[:table_filter] end
# File lib/taps/operation.rb, line 67 def to_hash { :klass => self.class.to_s, :database_url => database_url, :remote_url => remote_url, :session_uri => session_uri, :stream_state => stream_state, :completed_tables => completed_tables, :table_filter => table_filter, } end
# File lib/taps/operation.rb, line 169 def verify_server begin server['/'].get(http_headers) rescue RestClient::RequestFailed => e if e.http_code == 417 puts "#{safe_remote_url} is running a different minor version of taps." puts "#{e.response.to_s}" exit(1) else raise end rescue RestClient::Unauthorized puts "Bad credentials given for #{safe_remote_url}" exit(1) rescue Errno::ECONNREFUSED puts "Can't connect to #{safe_remote_url}. Please check that it's running" exit(1) end end
Generated with the Darkfish Rdoc Generator 2.