Sha256: e1a753a70817ce9839babd00bbb5a1e5509a4f835f90e51cf8b188764e68660d

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

# -*- coding: utf-8 -*-

module Arxutils
  def load_file( in_file )
    File.open( in_file , "r" , { :encoding => 'UTF-8' } )
  end
  
  def normalize_to_integer( *args )
    args.map{ |x|
      if x != nil and x !~ /^\s*$/
        x.to_i
      else
        nil
      end
    }
  end

  def update_integer( model , hs )
    value_hs = hs.reduce({}){ |hsx,item|
      val = model.send(item[0])
      if val == nil or val  < item[1]
        hsx[ item[0] ] = item[1]
      end
      hsx
    }
    if value_hs.size > 0
      begin
        model.update(value_hs)
      rescue => ex
        puts ex.message
      end
    end
  end

  def capture_queries(&block)
    queries = []
    ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, _start, _finish, _id, payload|
      queries << payload
    end
    yield block
    ActiveSupport::Notifications.unsubscribe('sql.active_record')
    queries
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arxutils-0.1.36 lib/arxutils/misc.rb
arxutils-0.1.35 lib/arxutils/misc.rb