Sha256: 4ad681f1c1c936f6b7110905c6d449f920c36aafaaa3e8f8693f3de39179951c

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

require 'benchmark'
require 'ostruct'

module MassInsert
  class ProcessControl

    attr_accessor :values, :options

    def initialize values, options
      @values  = values
      @options = options
    end

    # This method is responsible to call all the necessary process to
    # complete the mass insertion process and save the time each method
    # takes being executed.
    def start
      @build_time   = Benchmark.measure{ build_query }
      @execute_time = Benchmark.measure{ execute_query }
    end

    # Returns the correct query string  according to database adapter
    # previosly configured usually in database.yml in Rails project.
    def build_query
      @query = QueryBuilder.new(values, options).build
    end

    # This method does a QueryExecution instance where the query will be
    # execute. The query string is the instance variable @query.
    def execute_query
      QueryExecution.new(@query).execute if @query
    end

    # Provides an OpenStruc instance to see the process results. This
    # method is usually called from mass_insert_results in Base module.
    def results
      result = OpenStruct.new
      result.time         = @build_time.total + @execute_time.total
      result.records      = values.count
      result.build_time   = @build_time.total
      result.execute_time = @execute_time.total
      result
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mass_insert-0.1.1 lib/mass_insert/process_control.rb
mass_insert-0.1.0 lib/mass_insert/process_control.rb