Sha256: 0076b2a16340a23c9b8248b79c51f91c1ce81a33b7b10ac6c18a66385b1b126b
Contents?: true
Size: 1.29 KB
Versions: 17
Compression:
Stored size: 1.29 KB
Contents
require 'mysql2' module Services # = SQLSeedReader # # Load content from SQL seed. # class SQLSeedReader < SeedReader ## # == Read # # => Load the seed data into the @objects array for processing. # def read begin @client = Mysql2::Client.new(:host => @seed[:payload][:host], :username => @seed[:payload][:username] , :password => @seed[:payload][:password] , :database => @seed[:payload][:database]) @client.query(@seed[:payload][:query], :cast => false).each(:symbolize_keys => false) do |row| begin object = @help.deep_copy @agent[:payload] object.each_pair do |key,value| variables = @help.identify_variables(object[key]) variables.each do |v| object[key].gsub!("%{#{v}}", row[@seed[:payload][:selectors][v]].to_str) end end unless @seed[:payload][:cache].nil? then object[:seed] = row[@seed[:payload][:cache]] else object[:seed] = row["id"] end object[:identifier] = @agent.identifier @objects.push object rescue Exception => e end end rescue Exception => e end @objects end end end
Version data entries
17 entries across 17 versions & 2 rubygems