Sha256: 90e3aaba32883c41c00861c754af1a4ac6d4572710e7b7ef85041b469eaeabcd

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'slog'
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

1 entries across 1 versions & 1 rubygems

Version Path
i2x-0.0.3 lib/i2x/sqlseedreader.rb